Skip to content

Commit 9392d25

Browse files
committed
a
1 parent 7e9706c commit 9392d25

File tree

3 files changed

+82
-43
lines changed

3 files changed

+82
-43
lines changed

CF/algNotes/Breadth fitst search.md

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -58,44 +58,4 @@
5858

5959
- Number of Islands (1 more)
6060
- Knight Shortest Path (to-do)
61-
- Build Post Office II (to-do)
62-
63-
64-
```java
65-
public class Solution {
66-
/**
67-
* @param root: the root of the given tree
68-
* @return: the values of the nodes you can see ordered from top to bottom
69-
*/
70-
71-
72-
public List<Integer> rightSideView(TreeNode root) {
73-
// write your code here
74-
List<Integer> res = ArrayList<>();
75-
Queue <TreeNode> myQ = LinkedList<>();
76-
77-
if(root == null){
78-
return myQ;
79-
}
80-
81-
myQ.offer(root);
82-
return helper();
83-
}
84-
85-
public List<Integer> helper(){
86-
List<Integer> res = ArrayList<>();
87-
while(!myQ.isEmpty){
88-
int size = myQ.size();
89-
90-
for(int i = 0; i < size; i++){
91-
TreeNode node = myQ.poll();
92-
res.add(node.val);
93-
if(node.right != null){
94-
myQ.add(node.right);
95-
}
96-
}
97-
}
98-
return res;
99-
}
100-
}
101-
```
61+
- Build Post Office II (to-do)

CF/gp/gp1.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,39 @@ Sum(i~j) = PrefixSum[j + 1] - PrefixSum[i]
5959
- 415. Valid Palindrome
6060
## two pointer String
6161
- 637. valid Word Abbreviation
62-
- 415. Valid Palindrome
62+
- 415. Valid Palindrome
63+
64+
65+
66+
# BFS类问题
67+
- 二叉树上的宽搜 BFS in Binary Tree
68+
- 图上的宽搜 BFS in Graph
69+
- 拓扑排序 Topological Sorting
70+
- 棋盘上的宽搜 BFS
71+
72+
- When should use BFS?
73+
- 图的遍历 Traversal in Graph
74+
- 层级遍历 Level Order Traversal
75+
- 由点及面 Connected Component
76+
- 拓扑排序 Topological Sorting
77+
- 最短路径 Shortest Path in Simple Graph
78+
- 仅限简单图求最短路径
79+
- (图中每条边,没有方向,没有权重)
80+
## BFS in Binary Tree
81+
- Binary Tree Level Order Traversal
82+
- Serialize and Deserialize Binary Tree (1 more)
83+
- https://www.lintcode.com/help/binary-tree-representation/
84+
- Binary Tree Level Order Traversal II
85+
- Binary Tree Zigzag Order Traversal
86+
- Convert Binary Tree to Linked Lists by Depth
87+
## BFS in graph (Undirected)
88+
- 433. Number of Islands
89+
- Knight Shortest Path (to-do)
90+
- Build Post Office II (to-do)
91+
- Clone graph
92+
- find all nodes
93+
- mapping old node to new node
94+
- conncet all edges (copy neighbors)
95+
- Graph Valid Tree
96+
## Minimum Spanning Tree
97+
- 589. Connecting Graph

CF/gp/hf1.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,5 +772,49 @@ private Point global_origin = null;
772772
map.get(cur).add(pre);
773773
}
774774
return map;
775-
}
775+
}
776+
777+
778+
779+
780+
public class Solution {
781+
/**
782+
* @param grid: a boolean 2D matrix
783+
* @return: an integer
784+
*/
785+
public int numIslands(boolean[][] grid) {
786+
// write your code here
787+
if(grid == null || grid.length == 0){
788+
return 0;
789+
}
790+
791+
int m = grid.length;
792+
System.out.println(m);
793+
int n = grid[0].length;
794+
System.out.println(n);
795+
int res = 0;
796+
797+
for(int i = 0; i < m; i++){
798+
for(int j = 0; j < n; j++){
799+
if(grid[i][j]){
800+
dfs(grid, i,j,m,n);
801+
res++;
802+
}
803+
}
804+
}
805+
806+
return res;
807+
}
808+
809+
private void dfs(boolean[][] grid,int x, int y, int m,int n){
810+
if(x >= m || y >= n || x < 0|| y < 0 || !grid[x][y]){
811+
return;
812+
}
813+
grid[x][y] = false;
814+
dfs(grid,x-1,y,m,n);
815+
dfs(grid,x+1,y,m,n);
816+
dfs(grid,x,y-1,m,n);
817+
dfs(grid,x,y+1,m,n);
818+
}
819+
}
776820
```

0 commit comments

Comments
 (0)