Locally returns correct value, on OJ gets different result


  • 0
    K
    class Solution:
    cache = {}
    # @return an integer
    def uniquePathsWithObstacles(self, mapa):
        if mapa[0][0] == 1:
            return 0
        return self.uniquePathsWork(mapa, len(mapa)-1, len(mapa[0])-1)
        
    def uniquePathsWork(self, mapa, m, n):
        if m == -1 or n == -1 or mapa[m][n] == 1:
            return 0
        if m == 0 and n == 0:
            return 1
        if (m, n) not in Solution.cache:
            Solution.cache[(m, n)] = self.uniquePathsWork(mapa, m-1, n) + self.uniquePathsWork(mapa, m, n-1)
        return Solution.cache[(m, n)]
    

    Testcase is: [[0, 0], [1, 0]]

    Solution is "1"

    Locally with python2 and python3 I get result "1".

    On LeetCode I get "2".

    Any idea why?

    s = Solution()
    print(s.uniquePathsWithObstacles([[0,0],[1,0]]))

  • 0

    Please read the FAQ about the question: "Why does my code produce a different output compared to my local environment?"


Log in to reply
 

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