代码改变世界

[LeetCode] questions conclustion_BFS, DFS

2018-07-17 01:37  Johnson_强生仔仔  阅读(536)  评论(0编辑  收藏  举报

BFS, DFS 的题目总结. 

Directed graph:

Directed Graph Loop detection and if not have, path to print all path.

Morris Traversal_ O(1) space to change binary tree to linked list

 TODO:

shorted path from start to end in undirected weighted graph (Djastra?)

Union find

 

 

BFS/DFS: (可以用BFS或者DFS的,主要还是遍历)

 [LeetCode] 733. Flood Fill_Easy tag: BFS     1

[LeetCode] 690. Employee Importance_Easy tag: BFS    1

[LeetCode] 529. Minesweeper_ Medium_ tag: BFS

[LeetCode] 200. Number of Islands_ Medium tag: BFS

[LeetCode] 133. Clone Graph_ Medium tag: BFS, DFS

[LeetCode] 1485. Clone Binary Tree With Random Pointer_ Medium tag: BFS, DFS

[LeetCode] 261. Graph Valid Tree _ Medium tag: BFS

[LeetCode] 301. Remove Invalid Parentheses_Hard tag:BFS

[LeetCode] 104. Maximum Depth of Binary Tree_Easy tag: DFS

[LeetCode] 695. Max Area of Island_Easy tag: DFS/BFS

[LeetCode] 827. Making A Large Island

[LeetCode] 490. The Maze_Medium tag: BFS/DFS

 [LeetCode] 130. Surrounded Regions_Medium tag: DFS

 

 

BFS(shortest path/distance, level traversal)

  • level traversal
  • one node to all other nodes in graph
  • 图上两点之间最短距离

[Leetcode] 863. All Nodes Distance K in Binary Tree_ Medium tag: BFS, Amazon     1

[LeetCode] 199. Binary Tree Right Side View_ Medium tag: BFS, Amazon

[LeetCode] 102. Binary Tree Level Order Traversal_Medium tag: BFS

[LeetCode] 429. N-ary Tree Level Order Traversal_ Easy

[LeetCode] 127. Word Ladder _Medium tag: BFS

[LeetCode] 675. Cut Off Trees for Golf Event_Hard tag: BFS

[LeetCode] 103. Binary Tree Zigzag Level Order Traversal _ Medium tag: BFS

[LeetCode] 101. Symmetric Tree_ Easy tag: BFS

[LeetCode] 513. Find Bottom Left Tree Value_ Medium tag: BFS

[LeetCode] 286. Walls and Gates_Medium tag: BFS

[LeetCode] 116&117. Populating Next Right Pointers in Each Node I&II_Medium tag: BFS(Dont know why leetcode tag it as DFS...)

[LeetCode] 310. Minimum Height Trees_Medium tag: BFS

 待整理 --------

2440. Create Components With Same Value

 待整理 --------

 

DFS

[LeetCode] 207 Course Schedule_Medium tag: BFS, DFS    1 

[LeetCode] 785. Is Graph Bipartite?_Medium tag: DFS, BFS

[LeetCode] 210. Course Schedule II

[LeetCode] 694. Number of Distinct Islands

[LeetCode] 711. Number of Distinct Islands II_hard tag: DFS

[LeetCode] 851. Loud and Rich_ Medium tag: DFS

[LeetCode] 112. Path Sum_Easy tag: DFS

[LeetCode] 114. Flatten Binary Tree to Linked List_Medium tag: DFS

[LeetCode] 257. Binary Tree Paths_ Easy tag: DFS

[LeetCode] 113. Path Sum II

[LeetCode] 437. Path Sum III_ Easy tag: DFS

[LeetCode] 124. Binary Tree Maximum Path Sum_ Hard tag: DFS recursive

[LeetCode] 687. Longest Univalue Path_Easy tag: DFS recursive

[LeetCode] 298. Binary Tree Longest Consecutive Sequence_Medium tag: DFS recursive

[LeetCode] 549. Binary Tree Longest Consecutive Sequence II_ Medium tag: DFS recursive

[LeetCode] 721. Accounts Merge_Medium tag: DFS recursive

[LeetCode] 111. Minimum Depth of Binary Tree_Easy tag:DFS

 [LeetCode] 110. Balanced Binary Tree_Easy tag: DFS

[LeetCode] 100. Same Tree_Easy tag: DFS

[LeetCode] 99. Recover Binary Search Tree

[LeetCode] 129. Sum Root to Leaf Numbers_Medium tag: DFS

[LeetCode] 559. Maximum Depth of N-ary Tree_Easy tag: DFS

[LeetCode] 98. Validate Binary Search Tree_Medium 

[LeetCode] 173. Binary Search Tree Iterator_Medium_tag: Binary Search Tree

[LeetCode] 700. Search in a Binary Search Treer_Easy_tag: Binary Search Tree

[LeetCode] 701. Insert into a Binary Search Tree_Medium_tag: Binary Search Tree

 [LeetCode] 79. Word Search_Medium tag: Backtracking, DFS

[Leetcode] 543. Diameter of Binary Tree_Easy Tag: DFS

[LeetCode] 297. Serialize and Deserialize Binary Tree_hard tag: DFS, Divide and Conquer

[LeetCode] 428. Serialize and Deserialize N-ary Tree_hard tag: DFS, Divide and Conquer

[LeetCode] 329. Longest Increasing Path in a Matrix_Hard tag: Dynamic Programming, DFS, Memoization

[LeetCode] 399. Evaluate Division_Medium tag: DFS

[LeetCode] 489. Robot Room Cleaner_Hard tag: DFS, backtracking

[LeetCode] 951. Flip Equivalent Binary Trees_Medium tag: DFS, divide and conquer

[LeetCode] 663. Equal Tree Partition_Medium tag: DFS, divide and conquer

[LeetCode] 54. Spiral Matrix_Medium tag: array, DFS

[LeetCode] 59. Spiral Matrix II_Medium tag: array, DFS

 

BFS & DFS

[LeetCode] 126. Word Ladder II_Hard tag: BFS&DFS