随笔分类 - leetcode
摘要:问题: 传送带依次传送weights数组上对应元素重量的货物。 限制每天最多传送X重量的货物,D天刚好传送完毕,请问这个限重X是多少。 Example 1: Input: weights = [1,2,3,4,5,6,7,8,9,10], D = 5 Output: 15 Explanation:
阅读全文
posted @ 2020-06-02 11:36
habibah_chang
摘要:问题: 给定原数组A,和操作数组queries 假设q=queries[i] 那么q的操作为:对A[q[1]]+=q[0] evensum为A的所有偶数元素之和,求每次操作后evensum的值,所组成的列表res Example 1: Input: A = [1,2,3,4], queries =
阅读全文
posted @ 2020-06-01 14:10
habibah_chang
摘要:问题: 给两个由[1~6]之间的数字构成的两个数组A,B 若对其中一个数组中的一些元素用另一个数组同样index的元素替换,使得这个数组的所有元素都相同, 求最小替换个数。 Example 1: Input: A = [2,1,2,4,2,2], B = [5,2,6,2,3,2] Output:
阅读全文
posted @ 2020-06-01 13:34
habibah_chang
摘要:问题: 给定数组,求满足锯齿形子数组<连续两两元素的增减关系为:增减依次循环出现>的最大长度。 Example 1: Input: [9,4,2,10,7,8,8,1,9] Output: 5 Explanation: (A[1] > A[2] < A[3] > A[4] < A[5]) Examp
阅读全文
posted @ 2020-06-01 12:20
habibah_chang
摘要:问题: 给定数组,求给定区间中,出现次数>=threshold的元素值。 Example: MajorityChecker majorityChecker = new MajorityChecker([1,1,2,2,1,1]); majorityChecker.query(0,5,4); // r
阅读全文
posted @ 2020-05-31 16:55
habibah_chang
摘要:问题: 给定一个非减数组,求对其每个元素进行平方运算后,形成的非减数组。 Example 1: Input: [-4,-1,0,3,10] Output: [0,1,9,16,100] Example 2: Input: [-7,-3,2,3,11] Output: [4,9,9,49,121] N
阅读全文
posted @ 2020-05-31 13:16
habibah_chang
摘要:问题: 给定数组,求连续子数组之和能被K整除的,子数组个数。 Example 1: Input: A = [4,5,0,-2,-3,1], K = 5 Output: 7 Explanation: There are 7 subarrays with a sum divisible by K = 5
阅读全文
posted @ 2020-05-31 12:32
habibah_chang
摘要:问题: 斐波那契函数。 F(0) = 0, F(1) = 1 F(N) = F(N - 1) + F(N - 2), for N > 1.给定N,求解F(N) Example 1: Input: 2 Output: 1 Explanation: F(2) = F(1) + F(0) = 1 + 0
阅读全文
posted @ 2020-05-30 15:54
habibah_chang
摘要:问题: 给定数组,假定value=数组相邻元素两两之差(绝对值)的总和。 允许对数组内某一个连续子数组进行整体反转,使得value能取得最大。求这样的value。 Example 1: Input: nums = [2,3,1,5,4] Output: 10 Explanation: By reve
阅读全文
posted @ 2020-05-30 15:36
habibah_chang
摘要:问题: 给定数组, 假定反转动作k,表示:将数组前k个元素进行反转。 求反转动作k的序列,使得数组最终成为一个递增数组。(特:该数组为1~A.size()的一个排序) Example 1: Input: [3,2,4,1] Output: [4,2,4,3] Explanation: We perf
阅读全文
posted @ 2020-05-30 08:57
habibah_chang
摘要:问题: 给定数组,求一对 index为 ( i , j ) 的 A[i] <= A[j] && i < j,两个index距离最远。(即max(j-i)) Example 1: Input: [6,0,8,2,1,5] Output: 4 Explanation: The maximum width
阅读全文
posted @ 2020-05-29 14:59
habibah_chang
摘要:问题: 给定数组,是否从数组中选取元素,两两有二倍关系,刚好分配完所有的元素。 Example 1: Input: [3,1,3,6] Output: false Example 2: Input: [2,1,2,6] Output: false Example 3: Input: [4,-2,2,
阅读全文
posted @ 2020-05-28 11:44
habibah_chang
摘要:问题: 给一组数组,对其进行一个排序得到新的数组res,使得对res做一下操作最后得到target为一个递增数组。 1.取第一个数,到target数组。 2.把剩下的第一个数,排到原数组res最后。 3.重复1和2,直到原数组res为空。 Example 1: Input: [17,13,11,2,
阅读全文
posted @ 2020-05-27 11:23
habibah_chang
摘要:问题: 给定数组,给数组的一些值+1作为一个move,使得该数组成为一个没有重复元素的递增数组, 求最小的move。 Example 1: Input: [1,2,2] Output: 1 Explanation: After 1 move, the array could be [1, 2, 3]
阅读全文
posted @ 2020-05-26 15:15
habibah_chang
摘要:问题: 重新排序给定数组,使得下标index和数值A[index]的奇偶性一致。 Example 1: Input: [4,2,5,7] Output: [4,5,2,7] Explanation: [4,7,2,5], [2,5,4,7], [2,7,4,5] would also have be
阅读全文
posted @ 2020-05-25 15:49
habibah_chang
摘要:问题: 给定一个数组,如过将其中每X个相同的数组成一个group,正好分完,其中X>=2,成立的话,返回true,否则返回false Example 1: Input: deck = [1,2,3,4,4,3,2,1] Output: true Explanation: Possible parti
阅读全文
posted @ 2020-05-24 14:26
habibah_chang
摘要:问题: 给定01组成的字符串,求反转(0->1 or 1->0)最少次数,使得成为0...001..11(0..00 or 1..11)这样的单调增字符串。求反转次数。 Example 1: Input: "00110" Output: 1 Explanation: We flip the last
阅读全文
posted @ 2020-05-24 14:04
habibah_chang
摘要:问题: 给定数组,判断若为单调增(A[i]>=A[i-1])或者单调减(A[i]<=A[i-1])数组,则返回true,否则返回false。 Example 1: Input: [1,2,2,3] Output: true Example 2: Input: [6,5,4,4] Output: tr
阅读全文
posted @ 2020-05-24 10:57
habibah_chang
摘要:问题: 给定一个数组,其为循环数组(最后一个元素的下一个元素为第一个元素)。 求连续子数组和的最大值。 Example 1: Input: [1,-2,3,-2] Output: 3 Explanation: Subarray [3] has maximum sum 3 Example 2: Inp
阅读全文
posted @ 2020-05-23 17:21
habibah_chang
摘要:问题: 给定数组,切分为left和right,使得left的所有元素<=right的所有元素,返回left的长度 Example 1: Input: [5,0,3,8,6] Output: 3 Explanation: left = [5,0,3], right = [8,6] Example 2:
阅读全文
posted @ 2020-05-23 11:54
habibah_chang

浙公网安备 33010602011771号