leetcode广度优先搜索
Bryan要加油
这个作者很懒,什么都没留下…
展开
-
797. All Paths From Source to Target[Medium](Leetcode每日一题-2021.08.25)
Problem原创 2021-09-01 20:22:23 · 192 阅读 · 0 评论 -
847. Shortest Path Visiting All Nodes[Hard](Leetcode每日一题-2021.08.06)--抄答案
ProblemYou have an undirected, connected graph of n nodes labeled from 0 to n - 1. You are given an array graph where graph[i] is a list of all the nodes connected with node i by an edge.Return the length of the shortest path that visits every node. You原创 2021-08-06 19:39:43 · 211 阅读 · 0 评论 -
LCP 07. 传递信息[Easy](Leetcode每日一题-2021.07.01)
Problem小朋友 A 在和 ta 的小伙伴们玩传信息游戏,游戏规则如下:有 n 名玩家,所有玩家编号分别为 0 ~ n-1,其中小朋友 A 的编号为 0每个玩家都有固定的若干个可传信息的其他玩家(也可能没有)。传信息的关系是单向的(比如 A 可以向 B 传信息,但 B 不能向 A 传信息)。每轮信息必须需要传递给另一个人,且信息可重复经过同一个人给定总玩家数 n,以及按 [玩家编号,对应可传递玩家编号] 关系组成的二维数组 relation。返回信息从小 A (编号 0 ) 经过 k 轮传原创 2021-07-03 21:05:31 · 413 阅读 · 0 评论 -
815. Bus Routes[Hard](Leetcode每日一题-2021.06.28)
Problem原创 2021-06-29 22:13:54 · 224 阅读 · 0 评论 -
909. Snakes and Ladders[Medium](Leetcode每日一题-2021.06.27)
Problem原创 2021-06-29 22:11:41 · 138 阅读 · 0 评论 -
773. Sliding Puzzle[Hard](Leetcode每日一题-2021.06.26)
ProblemOn a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square represented by 0.A move consists of choosing 0 and a 4-directionally adjacent number and swapping it.The state of the board is solved if and only if th原创 2021-06-29 22:10:32 · 294 阅读 · 0 评论 -
752. Open the Lock[Medium](Leetcode每日一题-2021.06.25)
ProblemYou have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’. The wheels can rotate freely and wrap around: for example we can turn ‘9’ to be ‘0’, or ‘0’ to be ‘9’. Each move cons原创 2021-06-26 19:32:27 · 159 阅读 · 0 评论 -
993. Cousins in Binary Tree[Easy](Leetcode每日一题-2021.05.17)
ProblemIn a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1.Two nodes of a binary tree are cousins if they have the same depth, but have different parents.We are given the root of a binary tree with unique va原创 2021-05-17 08:42:24 · 121 阅读 · 0 评论 -
103. Binary Tree Zigzag Level Order Traversal(Leetcode每日一题-2020.12.22)
ProblemGiven a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tree [3,9,20,null,null,15,7],return its zigzag lev原创 2020-12-22 20:39:34 · 127 阅读 · 0 评论 -
Leetcode 207. Course Schedule&210. Course Schedule II
207. Course ScheduleProblem原创 2020-11-22 19:58:54 · 127 阅读 · 0 评论 -
127. Word Ladder(Leetcode每日一题-2020.11.05)
ProblemGiven two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed at a time.Each transformed word must exist in the word原创 2020-11-06 22:09:59 · 163 阅读 · 0 评论 -
133. Clone Graph(Leetcode每日一题-2020.08.12)
ProblemGiven a reference of a node in a connected undirected graph.Return a deep copy (clone) of the graph.Each node in the graph contains a val (int) and a list (List[Node]) of its neighbors.Test case format:For simplicity sake, each node’s value is原创 2020-08-12 20:56:50 · 185 阅读 · 0 评论 -
207. Course Schedule(Leetcode每日一题-2020.08.04)
ProblemThere are a total of numCourses courses you have to take, labeled from 0 to numCourses-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1]Given the total number原创 2020-08-04 22:44:03 · 195 阅读 · 0 评论 -
126. Word Ladder II(Leetcode每日一题-2020.06.07)
ProblemGiven two words (beginWord and endWord), and a dictionary’s word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:Only one letter can be changed at a timeEach transformed word must exist in the word list. N原创 2020-06-07 22:27:35 · 250 阅读 · 0 评论 -
199. Binary Tree Right Side View(Leetcode每日一题-2020.04.22)
占坑原创 2020-04-22 20:52:59 · 180 阅读 · 0 评论 -
200. Number of Islands(Leetcode每日一题-2020.04.20)
占坑原创 2020-04-20 21:01:33 · 234 阅读 · 0 评论 -
542. 01 Matrix(Leetcode每日一题-2020.04.15)
ProblemGiven a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example1Input:[[0,0,0],[0,1,0],[0,0,0]]Output:[[0,0,0...原创 2020-04-15 20:51:58 · 210 阅读 · 0 评论 -
面试题13. 机器人的运动范围(Leetcode每日一题-2020.04.08)
Problem地上有一个m行n列的方格,从坐标 [0,0] 到坐标 [m-1,n-1] 。一个机器人从坐标 [0, 0] 的格子开始移动,它每次可以向左、右、上、下移动一格(不能移动到方格外),也不能进入行坐标和列坐标的数位之和大于k的格子。例如,当k为18时,机器人能够进入方格 [35, 37] ,因为3+5+3+7=18。但它不能进入方格 [35, 38],因为3+5+3+8=19。请问该机...原创 2020-04-08 23:31:30 · 348 阅读 · 0 评论 -
1162. As Far from Land as Possible(Leetcode每日一题-2020.03.29)
ProblemGiven an N x N grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized and return th...原创 2020-03-30 20:05:56 · 318 阅读 · 0 评论 -
1302. Deepest Leaves Sum
ProblemGiven a binary tree, return the sum of values of its deepest leaves.ExampleInput: root = [1,2,3,4,5,null,6,7,null,null,null,null,8]Output: 15Solution2020-3-9,层序遍历。/** * Definition fo...原创 2020-03-09 23:00:46 · 192 阅读 · 0 评论 -
623. Add One Row to Tree
ProblemGiven the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. The root node is at depth 1.The adding rule is: given a positive i...原创 2020-03-08 22:25:24 · 136 阅读 · 0 评论 -
515. Find Largest Value in Each Tree Row
ProblemYou need to find the largest value in each row of a binary tree.ExampleSolution层序遍历变种题。/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left...原创 2020-03-08 11:45:06 · 97 阅读 · 0 评论 -
429. N-ary Tree Level Order Traversal
ProblemGiven an n-ary tree, return the level order traversal of its nodes’ values.Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by ...原创 2020-03-07 18:41:18 · 173 阅读 · 0 评论 -
面试题 04.03. List of Depth LCCI
ProblemGiven a binary tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g., if you have a tree with depth D, you’ll have D linked lists). Return a array containi...原创 2020-03-06 20:19:08 · 209 阅读 · 0 评论 -
994. Rotting Oranges(Leetcode每日一题-2020.03.04)
ProblemIn a given grid, each cell can have one of three values:the value 0 representing an empty cell;the value 1 representing a fresh orange;the value 2 representing a rotten orange.Every minu...原创 2020-03-04 19:52:26 · 273 阅读 · 0 评论 -
面试题32 - III. 从上到下打印二叉树 III
Problem请实现一个函数按照之字形顺序打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右到左的顺序打印,第三行再按照从左到右的顺序打印,其他行以此类推。Example给定二叉树: [3,9,20,null,null,15,7],返回其按之字形顺序层次遍历结果:Solution/**Definition for a binary tree node.struct...原创 2020-03-03 23:14:39 · 222 阅读 · 0 评论