随笔分类 -  leetcode

摘要:问题: 数组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,求得连续元素组成子数组最大值在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