原文链接: https://leetcode-cn.com/problems/maximum-lcci 英文原文Write a method that finds the maximum of two numbers. You should not use if-else or any other comparison operator. Example: Input: a = 1, b = 2 Output: 2 中文题目编写一个方法,找出两个数字a和b中最大的那一个。不得使用if-else或…
标签详情
数学 分类
原文链接: https://leetcode-cn.com/problems/operations-lcci 英文原文Write methods to implement the multiply, subtract, and divide operations for integers. The results of all of these are integers. Use only the add operator. You should implement following meth…
原文链接: https://leetcode-cn.com/problems/diving-board-lcci 英文原文You are building a diving board by placing a bunch of planks of wood end-to-end. There are two types of planks, one of length shorter and one of length longer. You must use exactly K planks…
原文链接: https://leetcode-cn.com/problems/bisect-squares-lcci 英文原文Given two squares on a two-dimensional plane, find a line that would cut these two squares in half. Assume that the top and the bottom sides of the square run parallel to the x-axis. Each…
原文链接: https://leetcode-cn.com/problems/best-line-lcci 英文原文Given a two-dimensional graph with points on it, find a line which passes the most number of points. Assume all the points that passed by the line are stored in list S sorted by their number. …
原文链接: https://leetcode-cn.com/problems/pattern-matching-lcci 英文原文You are given two strings, pattern and value. The pattern string consists of just the letters a and b, describing a pattern within a string. For example, the string catcatgocatgo matche…
原文链接: https://leetcode-cn.com/problems/factorial-zeros-lcci 英文原文Write an algorithm which computes the number of trailing zeros in n factorial. Example 1: Input: 3 Output: 0 Explanation: 3! = 6, no trailing zero. Example 2: Input: 5 Output: 1 Explanat…
原文链接: https://leetcode-cn.com/problems/add-without-plus-lcci 英文原文Write a function that adds two numbers. You should not use + or any arithmetic operators. Example: Input: a = 1, b = 1 Output: 2 Note: a and b may be 0 or negative. The result fits in 3…
原文链接: https://leetcode-cn.com/problems/calculator-lcci 英文原文Given an arithmetic equation consisting of positive integers, +, -, * and / (no paren­theses), compute the result. The expression string contains only non-negative integers, +, -, *, / op…
原文链接: https://leetcode-cn.com/problems/missing-number-lcci 英文原文An array contains all the integers from 0 to n, except for one number which is missing. Write code to find the missing integer. Can you do it in O(n) time? Note: This problem is slightly …
原文链接: https://leetcode-cn.com/problems/number-of-2s-in-range-lcci 英文原文Write a method to count the number of 2s that appear in all the numbers between 0 and n (inclusive). Example: Input: 25 Output: 9 Explanation: (2, 12, 20, 21, 22, 23, 24, 25)(Note …
原文链接: https://leetcode-cn.com/problems/get-kth-magic-number-lcci 英文原文Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7. Note that 3, 5, and 7 do not have to be factors, but it should not have any other prime …
原文链接: https://leetcode-cn.com/problems/na-ying-bi 英文原文 中文题目桌上有 n 堆力扣币,每堆的数量保存在数组 coins 中。我们每次可以选择任意一堆,拿走其中的一枚或者两枚,求拿完所有力扣币的最少次数。 示例 1: 输入:[4,2,1] 输出:4 解释:第一堆力扣币最少需要拿 2 次,第二堆最少需要拿 1 次,第三堆最少需要拿 1 次,总共 4 次即可拿完。 示例 2: 输入:[2,3,10] 输出:8 限制: 1 <= n <= 4 1 <…
原文链接: https://leetcode-cn.com/problems/qie-fen-shu-zu 英文原文 中文题目给定一个整数数组 nums ,小李想将 nums 切割成若干个非空子数组,使得每个子数组最左边的数和最右边的数的最大公约数大于 1 。为了减少他的工作量,请求出最少可以切成多少个子数组。 示例 1: 输入:nums = [2,3,3,2,3,3] 输出:2 解释:最优切割为 [2,3,3,2] 和 [3,3] 。第一个子数组头尾数字的最大公约数为 2 ,第二个子数组头尾数…
原文链接: https://leetcode-cn.com/problems/you-le-yuan-de-you-lan-ji-hua 英文原文 中文题目又到了一年一度的春游时间,小吴计划去游乐场游玩 1 天,游乐场总共有 N 个游乐项目,编号从 0 到 N-1。小吴给每个游乐项目定义了一个非负整数值 value[i] 表示自己的喜爱值。两个游乐项目之间会有双向路径相连,整个游乐场总共有 M 条双向路径,保存在二维数组 edges中。 小吴计划选择一个游乐项目 A 作为这一天游玩的重点项目。上…
原文链接: https://leetcode-cn.com/problems/qi-wang-ge-shu-tong-ji 英文原文 中文题目某互联网公司一年一度的春招开始了,一共有 n 名面试者入选。每名面试者都会提交一份简历,公司会根据提供的简历资料产生一个预估的能力值,数值越大代表越有可能通过面试。 小 A 和小 B 负责审核面试者,他们均有所有面试者的简历,并且将各自根据面试者能力值从大到小的顺序浏览。由于简历事先被打乱过,能力值相同的简历的出现顺序是从它们的全排列中等可能地取一个。现在…
原文链接: https://leetcode-cn.com/problems/you-le-yuan-de-mi-gong 英文原文 中文题目小王来到了游乐园,她玩的第一个项目是模拟推销员。有一个二维平面地图,其中散布着 N 个推销点,编号 0 到 N-1,不存在三点共线的情况。每两点之间有一条直线相连。游戏没有规定起点和终点,但限定了每次转角的方向。首先,小王需要先选择两个点分别作为起点和终点,然后从起点开始访问剩余 N-2 个点恰好一次并回到终点。访问的顺序需要满足一串给定的长度为 N-2 …
原文链接: https://leetcode-cn.com/problems/zui-xiao-ju-xing-mian-ji 英文原文 中文题目二维平面上有 $N$ 条直线,形式为 `y = kx + b`,其中 `k`、`b`为整数 且 `k > 0`。所有直线以 `[k,b]` 的形式存于二维数组 `lines` 中,不存在重合的两条直线。两两直线之间可能存在一个交点,最多会有 $C_N^2$ 个交点。我们用一个平行于坐标轴的矩形覆盖所有的交点,请问这个矩形最小面积是多少。若直线之间无交点…
原文链接: https://leetcode-cn.com/problems/5TxKeK 英文原文 中文题目小扣在秋日市集入口处发现了一个数字游戏。主办方共有 `N` 个计数器,计数器编号为 `0 ~ N-1`。每个计数器上分别显示了一个数字,小扣按计数器编号升序将所显示的数字记于数组 `nums`。每个计数器上有两个按钮,分别可以实现将显示数字加一或减一。小扣每一次操作可以选择一个计数器,按下加一或减一按钮。 主办方请小扣回答出一个长度为 N 的数组,第 i 个元素(0 <= i …
原文链接: https://leetcode-cn.com/problems/Uh984O 英文原文 中文题目小扣在秋日市集购买了一个古董键盘。由于古董键盘年久失修,键盘上只有 26 个字母 **a~z** 可以按下,且每个字母最多仅能被按 `k` 次。 小扣随机按了 n 次按键,请返回小扣总共有可能按出多少种内容。由于数字较大,最终答案需要对 1000000007 (1e9 + 7) 取模。 示例 1: 输入:k = 1, n = 1 输出:26 解释:由于只能按一次按键,所有可能的字符串为 …
原文链接: https://leetcode-cn.com/problems/nGK0Fy 英文原文 中文题目小扣在秋日市集发现了一款速算机器人。店家对机器人说出两个数字(记作 `x` 和 `y`),请小扣说出计算指令: - `"A"` 运算:使 `x = 2 * x + y`; - `"B"` 运算:使 `y = 2 * y + x`。 在本次游戏中,店家说出的数字为 x = 1 和 y = 0,小扣说出的计算指令记作仅由大写字母 A、B 组成的字符串 s,字符串中字符的顺序表示计算顺序,请返…
原文链接: https://leetcode-cn.com/problems/IQvJ9i 英文原文 中文题目秋日市集上有个奇怪的黑盒,黑盒的主视图为 n\*m 的矩形。从黑盒的主视图来看,黑盒的上面和下面各均匀分布有 m 个小孔,黑盒的左面和右面各均匀分布有 n 个小孔。黑盒左上角小孔序号为 0,按顺时针编号,总共有 2*(m+n) 个小孔。每个小孔均可以打开或者关闭,初始时,所有小孔均处于关闭状态。每个小孔上的盖子均为镜面材质。例如一个 2\*3 的黑盒主视图与其小孔分布如图所示: {:he…
原文链接: https://leetcode-cn.com/problems/SNJvJP 英文原文 中文题目某乐团的演出场地可视作 `num * num` 的二维矩阵 `grid`(左上角坐标为 `[0,0]`),每个位置站有一位成员。乐团共有 `9` 种乐器,乐器编号为 `1~9`,每位成员持有 `1` 个乐器。 为保证声乐混合效果,成员站位规则为:自 grid 左上角开始顺时针螺旋形向内循环以 1,2,...,9 循环重复排列。例如当 num = 5 时,站位如图所示 请返回位于…
原文链接: https://leetcode-cn.com/problems/Ju9Xwi 英文原文 中文题目小扣打算给自己的 **VS code** 安装使用插件,初始状态下带宽每分钟可以完成 `1` 个插件的下载。假定每分钟选择以下两种策略之一: - 使用当前带宽下载插件 - 将带宽加倍(下载插件数量随之加倍) 请返回小扣完成下载 n 个插件最少需要多少分钟。 注意:实际的下载的插件数量可以超过 n 个 示例 1: 输入:n = 2 输出:2 解释:以下两个方案,都能实现 2 分钟内下载 2…
原文链接: https://leetcode-cn.com/problems/xoh6Oh 中文题目给定两个整数 a 和 b ,求它们的除法的商 a/b ,要求不得使用乘号 '*'、除号 '/' 以及求余符号 '%' 。 注意: 整数除法的结果应当截去(truncate)其小数部分,例如:truncate(8.345) = 8 以及 truncate(-2.7335) = -2 假设我们的环境只能存储 32 位有符号整数,其数值范围是 [−231, 231−1]。本题中,…
原文链接: https://leetcode-cn.com/problems/JFETK5 中文题目给定两个 01 字符串 a 和 b ,请计算它们的和,并以二进制字符串的形式输出。 输入为 非空 字符串且只包含数字 1 和 0。 示例 1: 输入: a = "11", b = "10" 输出: "101" 示例 2: 输入: a = "1010", b = "1011" 输出: "10101" 提示: 每个字符串仅由字符 '0' 或 '1' 组成。 1 <= a.length, b.lengt…
原文链接: https://leetcode-cn.com/problems/lMSNwu 中文题目给定两个 非空链表 l1和 l2 来代表两个非负整数。数字最高位位于链表开始位置。它们的每个节点只存储一位数字。将这两数相加会返回一个新的链表。 可以假设除了数字 0 之外,这两个数字都不会以零开头。 示例1: 输入:l1 = [7,2,4,3], l2 = [5,6,4] 输出:[7,8,0,7] 示例2: 输入:l1 = [2,4,3], l2 = [5,6,4] 输出:[8,0,7] 示例3…
原文链接: https://leetcode-cn.com/problems/FortPu 中文题目设计一个支持在平均 时间复杂度 O(1) 下,执行以下操作的数据结构: insert(val):当元素 val 不存在时返回 true ,并向集合中插入该项,否则返回 false 。 remove(val):当元素 val 存在时返回 true ,并从集合中移除该项,否则返回 false 。 getRandom:随机返回现有集合中的一项。每个元素应该有 相同的概率 被返回。 示例 : 输入: in…
原文链接: https://leetcode-cn.com/problems/569nqc 中文题目给定一个 24 小时制(小时:分钟 "HH:MM")的时间列表,找出列表中任意两个时间的最小时间差并以分钟数表示。 示例 1: 输入:timePoints = ["23:59","00:00"] 输出:1 示例 2: 输入:timePoints = ["00:00","23:59","00:00"] 输出:0 提示: 2 <= timePoints <= 2 * 104 timePoints[i]…
原文链接: https://leetcode-cn.com/problems/8Zf90G 中文题目根据 逆波兰表示法,求该后缀表达式的计算结果。 有效的算符包括 +、-、*、/ 。每个运算对象可以是整数,也可以是另一个逆波兰表达式。 说明: 整数除法只保留整数部分。 给定逆波兰表达式总是有效的。换句话说,表达式总会得出有效数值且不存在除数为 0 的情况。 示例 1: 输入:tokens = ["2","1","+","3","*"] 输出:9 解释:该算式转化为常见的中缀算术表达式为:((2 …