随笔分类 - leetcode
摘要:问题: 扫雷问题:给定一个扫雷地图, 包含: M:埋雷cell E:空区cell X:已被挑出的雷cell 1~8:已被扫过的空区cell,该cell四周的埋雷数。 给出扫雷点击坐标click 求,这次click之后的扫雷地图的状态。 变化规则: M:变为X,扫到雷,游戏结束。 E:四周无雷:变为B
阅读全文
posted @ 2021-03-03 18:57
habibah_chang
摘要:问题: 给定二叉树,求每层最大节点,返回。 Example 1: Input: root = [1,3,2,5,3,null,9] Output: [1,3,9] Example 2: Input: root = [1,2,3] Output: [1,3] Example 3: Input: roo
阅读全文
posted @ 2021-03-03 12:46
habibah_chang
摘要:问题: 求给定二叉树,最底层最左边的节点值。 Example 1: Input: root = [2,1,3] Output: 1 Example 2: Input: root = [1,2,3,4,null,5,6,null,null,7] Output: 7 Constraints: The n
阅读全文
posted @ 2021-03-03 12:33
habibah_chang
摘要:问题: 给定一个二维数组,代表一块大陆的海拔, 数组左边和上边为太平洋,右边和下边为大西洋, 对于大陆上的每一个点,有水向海拔=<自己的方向流动,求既能流进太平洋,又能流进大西洋的坐标位置。 Example: Given the following 5x5 matrix: Pacific ~ ~ ~
阅读全文
posted @ 2021-03-02 17:13
habibah_chang
摘要:问题: 求给定无向图(树),从那个顶点作为root,得到最矮树。 Example 1: Input: n = 4, edges = [[1,0],[1,2],[1,3]] Output: [1] Explanation: As shown, the height of the tree is 1 w
阅读全文
posted @ 2021-03-02 13:57
habibah_chang
摘要:问题: 给定数字n,求将其分解为多个平方数的和,最少用多少个平方数可以得到。 Example 1: Input: n = 12 Output: 3 Explanation: 12 = 4 + 4 + 4. Example 2: Input: n = 13 Output: 2 Explanation:
阅读全文
posted @ 2021-03-01 17:41
habibah_chang
摘要:问题: 给定二维数组,每个格子: 0:代表不可行走,不可种树 1:代表可行走,未种树 x>1:代表,种了高x的树 从forest[0][0]开始出发,从最低高度的树开始砍伐,依次向更高的树前进进行砍伐。 问是否最终能砍完所有的树。 可以的话,返回行走步数。不可以的话,返回-1。 ⚠️ 注意:从[0]
阅读全文
posted @ 2021-02-28 11:58
habibah_chang
摘要:问题: 给定编号为0~numCourses-1 的课程,以及课程的依赖关系prerequisites 其中prerequisites[i] = [ai, bi],ai之前必须先上了bi的课程。 bi->ai 若能够上完所有的课程,给出一个上课顺序。 否则,返回空数组。 Example 1: Inpu
阅读全文
posted @ 2021-02-28 10:08
habibah_chang
摘要:问题: 给定二维数组,表示各个位置上建筑的高度。 求下雨累计雨量最多为多少? Example: Given the following 3x6 height map: [ [1,4,3,1,3,2], [3,2,1,3,2,4], [2,3,3,2,3,1] ] Return 4. The abov
阅读全文
posted @ 2021-02-27 13:15
habibah_chang
摘要:问题: 给定一个字符串,包含左右小括号+字母。 对该字符串进行【括号删减】,使得 字符串中括号完全匹配。"( )" 求最少删减字符,能得到的所有完全匹配的字符串。 Example 1: Input: "()())()" Output: ["()()()", "(())()"] Example 2:
阅读全文
posted @ 2021-02-27 11:20
habibah_chang
摘要:问题: 给定编号为:0~numCourses-1 ,numCourses门课。 以及课程依赖关系:prerequisites,prerequisites[x][0] 依赖 prerequisites[x][1] 即得先上 prerequisites[x][1] 课程,才能上prerequisites
阅读全文
posted @ 2021-02-26 15:32
habibah_chang
摘要:问题: 给定二叉树,求从右边观察这棵树,能看到的每层第一个元素。 Example 1: Input: root = [1,2,3,null,5,null,4] Output: [1,3,4] Example 2: Input: root = [1,null,3] Output: [1,3] Exam
阅读全文
posted @ 2021-02-26 13:26
habibah_chang
摘要:问题: 给定一个图,对该图进行深拷贝,返回拷贝出来的图。 adj[i]:代表节点 i 所相邻的节点。 Example 1: Input: adjList = [[2,4],[1,3],[2,4],[1,3]] Output: [[2,4],[1,3],[2,4],[1,3]] Explanation
阅读全文
posted @ 2021-02-25 14:35
habibah_chang
摘要:问题: 给定一个m*n棋盘,由O和X填入。 将棋盘中被X包围的O转化成X。 说明:在四周边缘的O,以及和这些O相邻(上下左右相邻)的O,无法转化。其他的棋盘内部O皆可转化为X。 Example 1: Input: board = [["X","X","X","X"],["X","O","O","X"
阅读全文
posted @ 2021-02-25 13:15
habibah_chang
摘要:问题: 给定二叉树,进行层序遍历,从底层向上输出。 Example 1: Input: root = [3,9,20,null,null,15,7] Output: [[15,7],[9,20],[3]] Example 2: Input: root = [1] Output: [[1]] Exam
阅读全文
posted @ 2021-02-25 11:26
habibah_chang
摘要:问题: 求二叉树的正反交替层序遍历。 第一层从左向右,第二次从右向左... Example 1: Input: root = [3,9,20,null,null,15,7] Output: [[3],[20,9],[15,7]] Example 2: Input: root = [1] Output
阅读全文
posted @ 2021-02-24 17:35
habibah_chang
摘要:问题: 求二叉树的层序遍历。 Example 1: Input: root = [3,9,20,null,null,15,7] Output: [[3],[9,20],[15,7]] Example 2: Input: root = [1] Output: [[1]] Example 3: Inpu
阅读全文
posted @ 2021-02-24 17:06
habibah_chang
摘要:问题: 给定一个公司的上下级关系 [id, importance, [subordinates]] [本员工id,本员工权值,[本员工的下属们的id]] 求给定员工id,的所有下属员工+自己的权值。 Example 1: Input: [[1, 5, [2, 3]], [2, 3, []], [3,
阅读全文
posted @ 2021-02-23 14:41
habibah_chang
摘要:问题: 将一组jobs分配给k个人,求完成这些job,最小需要的时间。 Example 1: Input: jobs = [3,2,3], k = 3 Output: 3 Explanation: By assigning each person one job, the maximum time
阅读全文
posted @ 2021-02-23 12:13
habibah_chang
摘要:问题: 给定一个数字n 则有一个1,从2~n各个数字两个。 进行排序,使得除了1之外任意两个相同数字直接的距离=数字自己。 得到一个字母序最大的解。 Example 1: Input: n = 3 Output: [3,1,2,3,2] Explanation: [2,3,2,1,3] is als
阅读全文
posted @ 2021-02-22 15:48
habibah_chang

浙公网安备 33010602011771号