My code run in my computer and when I submit it, I get compiler error

  • 0
    import collections
    from collections import deque
    class Solution:
        # @param board, a 2D array
        # Capture all regions by modifying the input board in-place.
        # Do not return any value.
        def solve(self, board):
            if n==0:return board
            if m==0:return board
            board=[[c for c in row] for row in board]
            #0 dont explored, 1 flip, 2 do not flip
            state=[[False]*m for i in range(n)]
            def check(v,n):
                return v>=0 and v<n
            def traverse(i,j,mark):
                while q:
                    if mark:board[ci][cj]='X'
                    for mi,mj in ((-1,0),(1,0),(0,1),(0,-1)):
                        if check(ni,n) and check(nj,m) and not state[ni][nj] and board[ni][nj]=='O':
            for j in range(m):
                if not state[0][j] and board[0][j]=='O':traverse(0,j,0);print j
                if not state[n-1][j] and board[n-1][j]=='O':traverse(n-1,j,0)
            for i in range(n):
                if not state[i][0] and board[i][0]=='O':traverse(i,0,0)
                if not state[i][m-1] and board[i][m-1]=='O':traverse(i,m-1,0)
            for i in range(n):
                for j in range(m):
                    if not state[i][j] and board[i][j]=='O':traverse(i,j,1)
            return board

    Hello, I have a problem with my python solution. In my laptop, the code run perfectly, but when I submit the solution, I got compiler error. I don't know why. My solution is simple, I just use a BFS.

  • 0

    do not import by yourself, just use the deque.

  • 0

    Thanks for help me. Best Regards

Log in to reply

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