Wrong in Leetcode but Correct in my local computer

  • 0

    The testcase ["a"] "a" runs ok in my local computer(returns true), but in leetcode it returns false. I don't know why.

    class Solution(object):
        used = [[0 for col in range(1000)] for row in range(1000)]
        def func(self, board, word, l, i, j, k):
            if k >= l:
                return True
            if i >= len(board) or i < 0 or j >= len(board[i]) or j < 0 or self.used[i][j] or board[i][j] != word[k]:
                return False
            self.used[i][j] = 1
            res = self.func(board, word, l, i+1, j, k+1) or self.func(board, word, l, i-1, j, k+1) or self.func(board, word, l, i, j-1, k+1) or self.func(board, word, l, i, j+1, k+1)
            if res:
                return True
            self.used[i][j] = 0
            return False
        def exist(self, board, word):
            :type board: List[List[str]]
            :type word: str
            :rtype: bool
            for i in xrange(len(board)):
                for j in xrange(len(board[0])):
                    if self.func(board, word, len(word), i, j, 0):
                        return True
            return False

Log in to reply

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