Skip to content

Commit f0af706

Browse files
edit 130
1 parent f6cb812 commit f0af706

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ Your ideas/fixes/algorithms are more than welcome!
419419
|134|[Gas Station](https://leetcode.com/problems/gas-station/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_134.java)| O(n)|O(1) | Medium| Greedy
420420
|133|[Clone Graph](https://leetcode.com/problems/clone-graph/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_133.java)| O(n)|O(n) | Medium| HashMap, BFS, Graph
421421
|132|[Implement Queue using Stacks](https://leetcode.com/problems/implement-queue-using-stacks/)|[Solution](../master/src/main/java/com/fishercoder/solutions/ImplementQueueUsingStacks.java)| O(n)|O(n) | Easy| Stack, Queue
422-
|130|[Surrounded Regions](https://leetcode.com/problems/surrounded-regions/)|[Solution](../master/src/main/java/com/fishercoder/solutions/SurroundedRegionsBFS.java)| O(?)|O(?) | Medium|
422+
|130|[Surrounded Regions](https://leetcode.com/problems/surrounded-regions/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_130.java)| O(?)|O(?) | Medium|
423423
|129|[Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers/)|[Solution](../master/src/main/java/com/fishercoder/solutions/SumRootToLeafNumbers.java)| O(n)|O(h) | Medium| DFS
424424
|127|[Word Ladder](https://leetcode.com/problems/word-ladder/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_127.java)| O(?)|O(?) | Medium| BFS
425425
|125|[Valid Palindrome](https://leetcode.com/problems/valid-palindrome/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_125.java)| O(n)|O(1) | Easy| Two Pointers

src/main/java/com/fishercoder/solutions/SurroundedRegionsBFS.java renamed to src/main/java/com/fishercoder/solutions/_130.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.*;
44

55
/**
6+
* 130. Surrounded Regions
7+
*
68
* Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.
79
810
A region is captured by flipping all 'O's into 'X's in that surrounded region.
@@ -12,17 +14,16 @@
1214
X O O X
1315
X X O X
1416
X O X X
17+
1518
After running your function, the board should be:
1619
1720
X X X X
1821
X X X X
1922
X X X X
2023
X O X X
21-
Show Tags
22-
Show Similar Problems
23-
2424
*/
25-
public class SurroundedRegionsBFS {
25+
public class _130 {
26+
2627
/**I won't call this problem hard, it's just confusing, you'll definitely want to clarify what the problem means before coding.
2728
* This problem eactually means:
2829
* any grid that is 'O' but on the four edges, will never be marked to 'X';
@@ -36,7 +37,8 @@ public void solve(char[][] board) {
3637
if(board == null || board.length == 0 || board[0].length == 0) return;
3738
int m = board.length, n = board[0].length;
3839
Queue<int[]> queue = new LinkedList();
39-
//check first row and last row and mark all those '0' on these two rows to be '+' to let them be different from other 'O', at the same time, we put them into the queue to get ready for a BFS to mark all those adjacent 'O' nodes to '+' as well
40+
//check first row and last row and mark all those '0' on these two rows to be '+' to let them be different from other 'O',
41+
//at the same time, we put them into the queue to get ready for a BFS to mark all those adjacent 'O' nodes to '+' as well
4042
for(int j = 0; j < n; j++){
4143
if(board[0][j] == 'O') {
4244
board[0][j] = '+';

0 commit comments

Comments
 (0)