05 2020 档案

摘要:问题: 给定数组,求给定区间中,出现次数>=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 编辑
摘要:问题: 数组A,和数组B,求交换两数组任意一个元素,使得两数组和相等。 返回{A交换出的元素,B交换出的元素} Example 1: Input: A = [1,1], B = [2,2] Output: [1,2] Example 2: Input: A = [1,2], B = [2,3] Ou 阅读全文
posted @ 2020-05-23 11:17 habibah_chang 编辑
摘要:问题: 给定数组,求所有连续子数组的最小值之和。 若所得之数太大,求其mod(10^9 + 7) Example 1: Input: [3,1,2,4] Output: 17 Explanation: Subarrays are [3], [1], [2], [4], [3,1], [1,2], [ 阅读全文
posted @ 2020-05-18 15:58 habibah_chang 编辑
摘要:问题: 以↘️对角线为轴,折叠反转数组 Example 1: Input: [[1,2,3],[4,5,6],[7,8,9]] Output: [[1,4,7],[2,5,8],[3,6,9]] Example 2: Input: [[1,2,3],[4,5,6]] Output: [[1,4],[ 阅读全文
posted @ 2020-05-17 14:31 habibah_chang 编辑
摘要:问题: 给定一个二维数组,求子数组之和为target的子数组个数。 Example 1: Input: matrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0 Output: 4 Explanation: The four 1x1 submatrices tha 阅读全文
posted @ 2020-05-17 14:06 habibah_chang 编辑
摘要:问题: 给定一个行程长度编码序列A,即偶数为代表下一位数的个数。 如A=[3,8,0,9,2,5],是序列【88855】的编码。 next(n)函数返回,对被编码序列消化n个数后最后消化的数值。实现初始化函数RLEIterator和next函数。 Example 1: Input: ["RLEIte 阅读全文
posted @ 2020-05-17 10:50 habibah_chang 编辑
摘要:问题: 给定0,1组成的数组,0代表空位,1代表有人坐,求使得坐在,跟最近坐的人距离最远,这个距离是多少。 Example 1: Input: [1,0,0,0,1,0,1] Output: 2 Explanation: If Alex sits in the second open seat (s 阅读全文
posted @ 2020-05-16 16:35 habibah_chang 编辑
摘要:问题: 给定数组,求所有子数组的最大值最小值之差的总和是多少。 这个数若太大了,对其进行取kMod=10^9+7的模 Example 1: Input: [2,1,3] Output: 6 Explanation: Subsequences are [1], [2], [3], [2,1], [2, 阅读全文
posted @ 2020-05-16 15:32 habibah_chang 编辑
摘要:问题: 给定一个递增数组,求其中所包含的斐波那契数列的长度。 A[i]+A[i+1]=A[i+2] Example 1: Input: [1,2,3,4,5,6,7,8] Output: 5 Explanation: The longest subsequence that is fibonacci 阅读全文
posted @ 2020-05-16 13:17 habibah_chang 编辑
摘要:问题: 给定两个size相同的数组A,B 对A进行排列,使得同位 i 上对数,A[i]>B[i],求使得满足这样条件元素最多的A的排列。 Example 1: Input: A = [2,7,11,15], B = [1,10,4,11] Output: [2,11,7,15] Example 2: 阅读全文
posted @ 2020-05-14 16:56 habibah_chang 编辑
摘要:问题: 给定数组,判断其中含有多少个3阶幻方 Example 1: Input: [[4,3,8,4], [9,5,1,9], [2,7,6,2]] Output: 1 Explanation: The following subgrid is a 3 x 3 magic square: 438 9 阅读全文
posted @ 2020-05-13 14:06 habibah_chang 编辑
摘要:问题: 给定两个大小相同,由0和1构成的N*N矩阵。求将其中一个矩阵进行水平垂直平移,最终两个矩阵重叠(1)的最大面积为多少。 Example 1: Input: A = [[1,1,0], [0,1,0], [0,1,0]] B = [[0,0,0], [0,1,1], [0,0,1]] Outp 阅读全文
posted @ 2020-05-13 11:23 habibah_chang 编辑
摘要:问题: 给定一个年龄数组,代表一组人的年龄,他们任何一个人A会向除了以下3个条件外的任意B发送好友请求,A->B age[B] <= 0.5 * age[A] + 7 age[B] > age[A] age[B] > 100 && age[A] < 100 请问,一共可能发送多少请求。 Exampl 阅读全文
posted @ 2020-05-12 17:15 habibah_chang 编辑
摘要:问题: 给定一个数组A,求得连续元素组成子数组最大值在L和R之间的子数组个数。 Example : Input: A = [2, 1, 4, 3] L = 2 R = 3 Output: 3 Explanation: There are three subarrays that meet the r 阅读全文
posted @ 2020-05-10 19:12 habibah_chang 编辑
摘要:问题: 给定一个字符串S,和一个词组集合words,返回words里的字符串为S的不连续字串的个数。 Example : Input: S = "abcde" words = ["a", "bb", "acd", "ace"] Output: 3 Explanation: There are thr 阅读全文
posted @ 2020-05-10 15:37 habibah_chang 编辑
摘要:问题: 给定一个由0,1组成的N*N的数组,问是否能进行多次行交换,列交换,使得数组成为一个国际象棋盘(01交叉排列) 可以则返回交换次数,否则返回-1 Examples: Input: board = [[0,1,1,0],[0,1,1,0],[1,0,0,1],[1,0,0,1]] Output 阅读全文
posted @ 2020-05-09 16:14 habibah_chang 编辑
摘要:问题: 给定一个由【0~N-1】组成的一个排列数组。 local降序:相邻两个元素逆序。 global降序:任意两个元素逆序。 若该数组local降序数=global降序数,则返回true, 反之返回false。 Example 1: Input: A = [1,0,2] Output: true 阅读全文
posted @ 2020-05-09 13:52 habibah_chang 编辑
摘要:问题: 给一个数组(这一题可以有重复的数字),我们将其最多分成几块,各自进行全排序,能得到整体有序的数列? 数值大小范围增大,元素个数增多 Example 1: Input: arr = [5,4,3,2,1] Output: 1 Explanation: Splitting into two or 阅读全文
posted @ 2020-05-06 15:18 habibah_chang 编辑
摘要:问题: 给一个[0~size()-1]排列的一个数组,我们将其最多分成几块,各自进行全排序,能得到整体有序的数列? Example 1: Input: arr = [4,3,2,1,0] Output: 1 Explanation: Splitting into two or more chunks 阅读全文
posted @ 2020-05-06 14:26 habibah_chang 编辑
摘要:问题: 给定一个二维数组, 若该数组的所有\方向的对角线数值相同,则为Toeplitz矩阵,返回true,否则返回false Example 1: Input: matrix = [ [1,2,3,4], [5,1,2,3], [9,5,1,2] ] Output: True Explanation 阅读全文
posted @ 2020-05-06 13:55 habibah_chang 编辑
摘要:问题: 给定数组,若存在最大值是任意其他元素的2倍以上,则返回该最大值的index,否则返回-1 Example 1: Input: nums = [3, 6, 1, 0] Output: 1 Explanation: 6 is the largest integer, and for every 阅读全文
posted @ 2020-05-06 13:33 habibah_chang 编辑
摘要:问题: 爬楼梯问题(经典动态规划DP问题) 给定每阶台阶的消耗数组,每次可以选择爬一阶或者两阶,求爬到顶楼的最小消耗。 Example 1: Input: cost = [10, 15, 20] Output: 15 Explanation: Cheapest is start on cost[1] 阅读全文
posted @ 2020-05-05 15:33 habibah_chang 编辑
摘要:问题: 求构造类Calendar,能够记录用户录入自己的日程,日程起止时间不能重合,重合则返回false。 Example 1: MyCalendar(); MyCalendar.book(10, 20); // returns true MyCalendar.book(15, 25); // re 阅读全文
posted @ 2020-05-05 15:06 habibah_chang 编辑
摘要:问题: 求给定数组的对称轴index。(其左边元素之和=右边元素之和) 若不存在则返回-1,若存在多个,返回最左边的对称轴。 Example 1: Input: nums = [1, 7, 3, 6, 5, 6] Output: 3 Explanation: The sum of the numbe 阅读全文
posted @ 2020-05-05 13:00 habibah_chang 编辑
摘要:问题: 求给定数组中两两元素之差,从小到大第k个差是多少 Example 1: Input: nums = [1,3,1] k = 1 Output: 0 Explanation: Here are all the pairs: (1,3) -> 2 (1,1) -> 0 (3,1) -> 2 Th 阅读全文
posted @ 2020-05-04 14:31 habibah_chang 编辑
摘要:问题: 给定两个数组,求两个数组中最长公共子数组的长度。 Example 1: Input: A: [1,2,3,2,1] B: [3,2,1,4,7] Output: 3 Explanation: The repeated subarray with maximum length is [3, 2 阅读全文
posted @ 2020-05-04 12:43 habibah_chang 编辑
摘要:问题: 解码问题,给出一串0,1数列, 遇到1,则由10或11解码为一个字符。 否则遇到0,则单独0解码为一个字符。求解码到最后一个字符是否由0解码而来。 (给出数列,总是以0为结尾) Example 1: Input: bits = [1, 0, 0] Output: True Explanati 阅读全文
posted @ 2020-05-04 11:30 habibah_chang 编辑

点击右上角即可分享
微信分享提示