Why I get different result when i ran my code in my computer and leetcode OJ


  • 0
    D
    class Solution:
        result = []
        def isvalid(self,num,value,board):
            for i in range(0,num):
                if value == board[i]:
                    return False
                elif value-board[i] == num-i or value-board[i] == i-num:
                    return False
            return True
            
        def genSolu(self,board):
            one = []
            size=len(board)
            for i in range(0,size):
                s = '.'*size
                l = list(s)
                l[board[i]]='Q'
                s = ''.join(l)
                one.append(s)
            self.result.append(one)
            
        def getQueue(self,num,board,n):
            if num==n:
                self.genSolu(board)
            for i in range(0,n):
                if self.isvalid(num,i,board):
                    board.append(i)
                    self.getQueue(num+1,board,n)
                    board.pop()
        # @return a list of lists of string
        def solveNQueens(self, n):
            board=[]
            self.getQueue(0,board,n)
            return self.result

  • 0
    X

    I have encountered the same problem for several times. But haven't figured out why.


Log in to reply
 

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