随笔分类 -  graph(bfs)

803. Bricks Falling When Hit
摘要:看不懂 union find 的代码 https://leetcode.com/problems/bricks-falling-when-hit/discuss/141229/JAVA-Simple-DFS-16ms-reversely-add-bricks-back Very clever idea using -1 to stop visiting the points already ... 阅读全文

posted @ 2018-11-08 16:58 猪猪🐷

752. Open the Lock
摘要:each time, can only change one of the four positions. And for each position, can only change either + 1 , or - 1 use "+ 10 mod 10" to guarentee a posi 阅读全文

posted @ 2018-11-08 15:44 猪猪🐷

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. Example 1: Input: n = 5, and edg... 阅读全文

posted @ 2018-11-06 09:41 猪猪🐷

310. Minimum Height Trees
摘要:https://leetcode.com/problems/minimum-height-trees/discuss/76055/Share-some-thoughts For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a... 阅读全文

posted @ 2018-11-06 09:09 猪猪🐷

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 0 0 1 0 0 0 0 Output: 0 0 0 0 1 0 0 0 0 Exa... 阅读全文

posted @ 2018-11-06 09:08 猪猪🐷

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 roll 阅读全文

posted @ 2018-11-06 08:44 猪猪🐷

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 roll 阅读全文

posted @ 2018-11-06 08:43 猪猪🐷

529. Minesweeper
摘要:Example 2: 阅读全文

posted @ 2018-09-25 04:18 猪猪🐷

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. Example: X X X X X O O X ... 阅读全文

posted @ 2018-09-20 18:23 猪猪🐷

815. Bus Routes
摘要:We have a list of bus routes. Each routes[i] is a bus route that the i-th bus repeats forever. For example if routes[0] = [1, 5, 7], this means that t 阅读全文

posted @ 2018-08-30 03:28 猪猪🐷

886. Possible Bipartition
摘要:Given a set of N people (numbered 1, 2, ..., N), we would like to split everyone into two groups of anysize. Each person may dislike some other people 阅读全文

posted @ 2018-08-28 20:47 猪猪🐷

301. Remove Invalid Parentheses
摘要:301. Remove Invalid Parentheses Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results. Note: The input string may contain letters oth... 阅读全文

posted @ 2018-08-16 23:44 猪猪🐷

133. Clone Graph
摘要:Given the head of a graph, return a deep copy (clone) of the graph. Each node in the graph contains a label (int) and a list (List[UndirectedGraphNode 阅读全文

posted @ 2018-08-11 03:54 猪猪🐷

Find Shortest distance from a guard in a Bank.
摘要:Given a matrix that is filled with ‘O’, ‘G’, and ‘W’ where ‘O’ represents open space, ‘G’ represents guards and ‘W’ represents walls in a Bank. Replac 阅读全文

posted @ 2018-08-11 03:51 猪猪🐷

126 Word Ladder II
摘要:126. Word Ladder II Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that: 1. Only one letter can... 阅读全文

posted @ 2018-08-10 15:12 猪猪🐷

127 Word Ladder
摘要:Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, 阅读全文

posted @ 2018-08-10 14:39 猪猪🐷

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 阅读全文

posted @ 2018-08-09 19:07 猪猪🐷

733. Flood Fill
摘要:An image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535). Given a coordinate (sr, 阅读全文

posted @ 2018-08-09 19:06 猪猪🐷

317. Shortest Distance from All Buildings
摘要:You want to build a house on an empty land which reaches all buildings in the shortest amount of distance. You can only move up, down, left and right. 阅读全文

posted @ 2018-08-09 19:04 猪猪🐷

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 阅读全文

posted @ 2018-08-09 17:52 猪猪🐷

导航