We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 38ac46e commit 12288f2Copy full SHA for 12288f2
P104. 被围绕的区域.md
@@ -0,0 +1,39 @@
1
+
2
+
3
+```
4
+class Solution:
5
+ def solve(self, board: List[List[str]]) -> None:
6
+ """
7
+ Do not return anything, modify board in-place instead.
8
9
+ m = len(board)
10
+ n = len(board[0])
11
12
+ def dfs(i,j):
13
+ if not 0<=i<m or not 0<=j<n or board[i][j] != 'O':
14
+ return
15
+ board[i][j] = 'A'
16
+ #情况1
17
+ dfs(i+1,j)
18
+ #情况2
19
+ dfs(i-1,j)
20
+ #情况3
21
+ dfs(i,j+1)
22
+ #情况4
23
+ dfs(i,j-1)
24
25
+ for i in range(m):
26
+ dfs(i,0)
27
+ dfs(i,n-1)
28
29
+ for j in range(n):
30
+ dfs(0, j)
31
+ dfs(m-1, j)
32
33
34
35
+ if board[i][j] == 'A':
36
+ board[i][j] = 'O'
37
+ elif board[i][j] == 'O':
38
+ board[i][j] = 'X'
39
images/algo43.jpg
51 KB
0 commit comments