
Breadth-first Search
文章平均质量分 79
zshouyi
这个作者很懒,什么都没留下…
展开
-
101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3原创 2017-02-06 15:53:24 · 192 阅读 · 0 评论 -
407. Trapping Rain Water II
Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevation map, compute the volume of water it is able to trap after raining.Note:Both m and n are l原创 2017-06-21 08:28:51 · 275 阅读 · 0 评论 -
261. Graph Valid Tree
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.For example:Given n =原创 2017-06-10 05:08:42 · 338 阅读 · 0 评论 -
323. Number of Connected Components in an Undirected Graph
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to find the number of connected components in an undirected graph.Example 1:原创 2017-06-10 05:27:06 · 582 阅读 · 0 评论 -
490. The Maze
There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, i原创 2017-06-10 07:58:27 · 919 阅读 · 0 评论 -
505. The Maze II
There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, i原创 2017-06-10 08:02:50 · 741 阅读 · 0 评论 -
542. 01 Matrix
Given 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.Example 1: Input:0 0 00 1 00 0 0Output:0 0 00 1 00原创 2017-06-14 03:02:37 · 408 阅读 · 0 评论 -
529. Minesweeper
Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix representing the game board. 'M' represents an unrevealed mine, 'E' represents an unrevealed empty squa原创 2017-06-14 10:51:59 · 329 阅读 · 0 评论 -
130. Surrounded Regions
Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,原创 2017-06-14 12:30:41 · 268 阅读 · 0 评论 -
286. Walls and Gates
You are given a m x n 2D grid initialized with these three possible values.-1 - A wall or an obstacle.0 - A gate.INF - Infinity means an empty room. We use the value 231 - 1 = 2147483647 to repr原创 2017-06-15 01:53:46 · 353 阅读 · 0 评论 -
417. Pacific Atlantic Water Flow
Given an m x n matrix of non-negative integers representing the height of each unit cell in a continent, the "Pacific ocean" touches the left and top edges of the matrix and the "Atlantic ocean" tou原创 2017-06-08 14:18:47 · 254 阅读 · 0 评论 -
200. Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assu原创 2017-06-04 14:01:30 · 312 阅读 · 0 评论 -
513. Find Bottom Left Tree Value
Given a binary tree, find the leftmost value in the last row of the tree. Example 1:Input: 2 / \ 1 3Output:1Example 2: Input: 1 / \ 2 3原创 2017-06-03 05:50:54 · 286 阅读 · 0 评论 -
111. Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.这里用递归解法,分了5种返回情况,详见代码,代码如下:/** *原创 2017-02-08 13:13:16 · 202 阅读 · 0 评论 -
107. Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,null,null,1原创 2017-02-10 04:30:11 · 357 阅读 · 0 评论 -
102. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 2原创 2017-02-10 04:39:37 · 234 阅读 · 0 评论 -
103. Binary Tree Zigzag Level Order Traversal
Given 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原创 2017-05-17 12:08:07 · 268 阅读 · 0 评论 -
199. Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1原创 2017-05-30 06:09:32 · 199 阅读 · 0 评论 -
133. Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for ea原创 2017-06-05 01:44:13 · 266 阅读 · 0 评论 -
207. Course Schedule
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as原创 2017-06-05 09:01:01 · 263 阅读 · 0 评论 -
210. Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as原创 2017-06-06 09:27:00 · 316 阅读 · 0 评论 -
515. Find Largest Value in Each Tree Row
You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]层序遍历找每层的最大值。代码如下:原创 2017-06-03 05:36:06 · 226 阅读 · 0 评论 -
310. Minimum Height Trees
For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called mini原创 2017-06-15 03:15:04 · 285 阅读 · 0 评论