MCPcopy
hub / github.com/qiyuangong/leetcode / solve

Method solve

python/130_Surrounded_Regions.py:2–16  ·  view source on GitHub ↗
(self, board)

Source from the content-addressed store, hash-verified

1class Solution(object):
2 def solve(self, board):
3 # https://discuss.leetcode.com/topic/22503/some-tips-for-python-code
4 if not board:
5 return
6 height, width = len(board), len(board[0])
7 leakWall = self.buildLeakWall(board)
8 while leakWall:
9 i, j = leakWall.pop()
10 if 0 <= i < height and 0 <= j < width:
11 if board[i][j] == "O":
12 board[i][j] = "S"
13 leakWall += (i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)
14 for i in range(height):
15 for j in range(width):
16 board[i][j] = "O" if board[i][j] == "S" else "X"
17
18 def buildLeakWall(self, board):
19 leakWall, height, width = [], len(board), len(board[0])

Callers

nothing calls this directly

Calls 2

buildLeakWallMethod · 0.95
popMethod · 0.45

Tested by

no test coverage detected