Skip to content

Commit e7e9c79

Browse files
committed
Update solution 130
1 parent 39d3850 commit e7e9c79

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

solution/130.Surrounded Regions/README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Solution {
3838
int x;
3939
int y;
4040

41-
public Point(int x, int y) {
41+
Point(int x, int y) {
4242
this.x = x;
4343
this.y = y;
4444
}
@@ -91,9 +91,8 @@ class Solution {
9191

9292
while (!queue.isEmpty()) {
9393
Point p = queue.poll();
94-
// 获取下一层所有有效坐标点
94+
// 获取下一层所有有效坐标点,并加入队列
9595
List<Point> points = getNextLevelValidPoints(board, p.x, p.y);
96-
9796
for (Point point : points) {
9897
queue.offer(point);
9998
}
@@ -132,7 +131,7 @@ class Solution {
132131
int m = board.length;
133132
int n = board[0].length;
134133
// 当前坐标对应的值是'O',才算有效
135-
return (i < 0 || i > m - 1 || j < 0 || j > n - 1 || board[i][j] != 'O') ? false : true;
134+
return i >= 0 && i <= m - 1 && j >= 0 && j <= n - 1 && board[i][j] == 'O';
136135
}
137136

138137
}

solution/130.Surrounded Regions/Solution.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ private class Point {
77
int x;
88
int y;
99

10-
public Point(int x, int y) {
10+
Point(int x, int y) {
1111
this.x = x;
1212
this.y = y;
1313
}
@@ -46,7 +46,6 @@ public void solve(char[][] board) {
4646

4747
/**
4848
* 广度优先搜索
49-
*
5049
* @param board
5150
* @param i
5251
* @param j
@@ -61,9 +60,8 @@ private void bfs(char[][] board, int i, int j) {
6160

6261
while (!queue.isEmpty()) {
6362
Point p = queue.poll();
64-
// 获取下一层所有有效坐标点
63+
// 获取下一层所有有效坐标点,并加入队列
6564
List<Point> points = getNextLevelValidPoints(board, p.x, p.y);
66-
6765
for (Point point : points) {
6866
queue.offer(point);
6967
}
@@ -73,7 +71,6 @@ private void bfs(char[][] board, int i, int j) {
7371

7472
/**
7573
* 获取下一层所有有效坐标点,将这些坐标点修改为 'Y' 并返回
76-
*
7774
* @param board
7875
* @param i
7976
* @param j
@@ -94,7 +91,6 @@ private List<Point> getNextLevelValidPoints(char[][] board, int i, int j) {
9491

9592
/**
9693
* 判断坐标是否有效
97-
*
9894
* @param board
9995
* @param i
10096
* @param j
@@ -104,7 +100,7 @@ private boolean isValid(char[][] board, int i, int j) {
104100
int m = board.length;
105101
int n = board[0].length;
106102
// 当前坐标对应的值是'O',才算有效
107-
return (i < 0 || i > m - 1 || j < 0 || j > n - 1 || board[i][j] != 'O') ? false : true;
103+
return i >= 0 && i <= m - 1 && j >= 0 && j <= n - 1 && board[i][j] == 'O';
108104
}
109105

110106
}

0 commit comments

Comments
 (0)