随笔分类 -  leetcode

上一页 1 2 3 4 5 6 7 8 9 ··· 19 下一页
摘要:问题: 给定n*n的二维数组, board[i][j]:每个格子代表,到达该格子后的下一个位置。 ⚠️ 注意:位置标记:从最后一行第一个开始,标记为 1 开始,成Z字形向上,依次递增。直到第一行第一个格子位置为 n*n。 若board[i][j] 1,(假设当前位置标记为x)那么它的下一个位置可以为 阅读全文
posted @ 2021-03-13 10:07 habibah_chang
摘要:问题: 给定N叉树,求该树的最大深度。 Example 1: Input: root = [1,null,3,2,4,null,5,6] Output: 3 Example 2: Input: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10 阅读全文
posted @ 2021-03-10 16:46 habibah_chang
摘要:问题: 给定二叉树, root坐标为(0,0), 对于任意节点 (x,y), 其左孩子(x+1, y-1), 右孩子(x+1, y+1) 按照列输出节点。(从左到右,对于每一列,从上到下) 若多个节点坐标相同,则按照值从小到大进行输出。 Example 1: Input: root = [3,9,2 阅读全文
posted @ 2021-03-10 14:26 habibah_chang
摘要:问题: 给定一个无向图,节点0~N-1 mouse:从1出发-> 到达 0,win -> return 1 cat:从2出发-> 到达mouse的当前位置,win(不能走 0 节点)-> return 2 若两者都无法win,且走完所有的节点,那么平局 tie。-> return 0 ⚠️ 注意: 阅读全文
posted @ 2021-03-10 11:40 habibah_chang
摘要:问题: 给定一棵二叉树, 求距离root最远距离d,所有节点所在的公共父节点。 Example 1: Input: root = [3,5,1,6,2,0,8,null,null,7,4] Output: [2,7,4] Explanation: We return the node with va 阅读全文
posted @ 2021-03-09 15:28 habibah_chang
摘要:问题: 给定一个无向图,n个节点 每条边可分为0个or多个node, 求从节点0开始,走maxMoves步,总共能经过多少个node。 Example 1: Input: edges = [[0,1,10],[0,2,1],[1,2,2]], maxMoves = 6, n = 3 Output: 阅读全文
posted @ 2021-03-09 13:15 habibah_chang
摘要:问题: 给定一个迷宫数组: @:起点 #:墙壁 a~f:key A~F:lock 从起点开始走,遇到key,可以拾得,用于开启后续遇到的lock,(若遇到lock前没有拾得对应key,那么无法通过) 墙壁也无法通过。求要获得所有的key,最少走的步数。 不可能获得所有的key的话,返回-1。 Exa 阅读全文
posted @ 2021-03-09 10:16 habibah_chang
摘要:问题: 给定一棵二叉树。 求给定节点target开始,距离K的所有节点。 Example 1: Input: root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, K = 2 Output: [7,4,1] Explanation: The nodes 阅读全文
posted @ 2021-03-08 11:40 habibah_chang
摘要:问题: 给定一个字符串A,每次交换其中两个字符, 最后使得到字符串B,求最少交换次数。 Example 1: Input: A = "ab", B = "ba" Output: 1 Example 2: Input: A = "abc", B = "bca" Output: 2 Example 3: 阅读全文
posted @ 2021-03-08 10:09 habibah_chang
摘要:问题: 给定一个图,graph[i]代表节点 i 相连的各个节点。 求遍历完所有节点,所需要的最小路径花费。 ⚠️ 注意:可以重复经过同一条边or同一个节点。 Example 1: Input: [[1,2,3],[0],[0],[0]] Output: 4 Explanation: One pos 阅读全文
posted @ 2021-03-08 09:14 habibah_chang
摘要:问题: 给定m*n的二维数组,由0和1构成。 1代表陆地,0代表海洋。 求在任意一个0的位置填上陆地 1,使得获得最大面积陆地,求这个陆地的面积。 Example 1: Input: grid = [[1,0],[0,1]] Output: 3 Explanation: Change one 0 t 阅读全文
posted @ 2021-03-07 13:22 habibah_chang
摘要:问题: 给定多条bus线路,routes[i]代表 bus i 的所有经停站点。 给定source起始站,和target目标站,求最少换乘几辆车能到达目的地。 Example 1: Input: routes = [[1,2,7],[3,6,7]], source = 1, target = 6 O 阅读全文
posted @ 2021-03-07 11:54 habibah_chang
摘要:问题: 给定n个地点,以及地点之间的航班和费用。 求从src到dst,中转最多k次以内,花费最少的费用。 Example 1: Input: n = 3, edges = [[0,1,100],[1,2,100],[0,2,500]] src = 0, dst = 2, k = 1 Output: 阅读全文
posted @ 2021-03-07 11:15 habibah_chang
摘要:问题: 滑动拼图。 给定2*3的一个拼图,有1~5代表每个格子的拼图,0代表空,其他位置的拼图可以滑动到这里。 求给定现在状态的拼图,是否最终能滑动到 1 2 3 4 5 0 的状态。 可以的话,需要最少多少步。 不可以的话,返回-1。 Examples: Input: board = [[1,2, 阅读全文
posted @ 2021-03-06 16:32 habibah_chang
摘要:转载:转载请注明出处:勿在浮沙筑高台http://blog.csdn.net/luoshixian099/article/details/51908175 一.Prim算法 适用于:边较多时 加点法: 时间复杂度:O(V^2) 在已得最小生成树各个节点,(绿色set:A,C,G) 向外部其他节点的节 阅读全文
posted @ 2021-03-06 13:01 habibah_chang
摘要:问题: 给定一个无向图,graph[i]={a,b,c...} 代表:节点 i 的邻接节点有 节点 a,b,c... ⚠️ 这里若有graph[a]中包含b,那么graph[b]中也包含a。 求将这个图中的节点分为两个集合, 任意相邻两个节点,都分别位于两个集合中。 是否能行。 Example 1: 阅读全文
posted @ 2021-03-05 15:49 habibah_chang
摘要:问题: 给定N叉树,将各个节点的值,按【层】构成数组输出。 Example 1: Input: root = [1,null,3,2,4,null,5,6] Output: [[1],[3,2,4],[5,6]] Example 2: Input: root = [1,null,2,3,4,5,nu 阅读全文
posted @ 2021-03-05 15:10 habibah_chang
摘要:转载:[图的最短路径算法]Dijkstra, Bellman-Ford, Floyd-Warshall 一. Dijkstra算法 ⚠️ 注意:不能解决含有负权的图。 S[v]标记已访问(红色节点):queue.pop后,再标记已访问。 priority_queue优先队列:优先处理最短节点。 di 阅读全文
posted @ 2021-03-05 11:29 habibah_chang
摘要:问题: 给定n个节点,节点到节点所需要耗费的时间,从给定节点k开始, 最少花多长时间遍历完所有节点。 Example 1: Input: times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2 Output: 2 Example 2: Input: times 阅读全文
posted @ 2021-03-04 17:40 habibah_chang
摘要:问题: 给定一个由 0 和 1 构成的二维数组。 求每个cell到最近0的距离。 Example 1: Input: [[0,0,0], [0,1,0], [0,0,0]] Output: [[0,0,0], [0,1,0], [0,0,0]] Example 2: Input: [[0,0,0], 阅读全文
posted @ 2021-03-04 15:02 habibah_chang

上一页 1 2 3 4 5 6 7 8 9 ··· 19 下一页