Why my code got runtime error?


  • 0
    M

    class Solution:
    # @param board, a 9x9 2D array
    # Capture all regions by modifying the input board in-place.
    # Do not return any value.
    def solve(self, board):
    if not board:
    return
    self.row = len(board)
    self.column = len(board[0])
    for x in xrange(self.row):
    self.dfs(x,0,board)
    self.dfs(x,self.column-1,board)
    for y in xrange(self.column):
    self.dfs(0,y,board)
    self.dfs(self.row-1,y,board)
    for x in xrange(self.row):
    for y in xrange(self.column):
    if board[x][y] =='O':
    board[x][y] = 'X'
    if board[x][y] =='d':
    board[x][y] = 'O'
    return
    def dfs(self,x,y,board):
    if x>=self.row or x<0 or y>=self.column or y<0 or board[x][y]!='O':
    return
    board[x][y] = 'd'
    self.dfs(x-1,y,board)
    self.dfs(x+1,y,board)
    self.dfs(x,y-1,board)
    self.dfs(x,y+1,board)


  • 0
    X

    you can use bfs, dont use dfs,


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.