Weird Python bug, "Run Code" doesn't match "Submit Solution"


  • 0
    D
    def pacificAtlantic(self, matrix):
    	def reachable(ocean, r,c):
    		if (r,c) not in ocean:
    			visited.add((r,c))
    			ocean[r,c] = any(
    				reachable(ocean, newr, newc)
    				for newr, newc in [[r-1,c], [r+1,c], [r,c-1], [r,c+1]]
    				if 0 <= newr < m
    				and 0 <= newc < n
    				and (newr, newc) not in visited
    				and matrix[r][c] >= matrix[newr][newc])
    			visited.remove((r,c))
    		return ocean[r,c]
    
    	if not matrix or not matrix[0]:
    		return []
    	m,n = len(matrix), len(matrix[0])
    	pacific = {}
    	atlantic = {}
    	for r in xrange(m):
    		pacific[r,0] = True
    		atlantic[r,n-1] = True
    	for c in xrange(n):
    		pacific[0,c] = True
    		atlantic[m-1,c] = True
    	visited = set()
    	print reachable(pacific,3,27), reachable(atlantic,3,27)
    	return [
    		[r,c] for r in xrange(m) for c in xrange(n)
    		if reachable(pacific,r,c) and reachable(atlantic,r,c)]
    

    Here is my code. Please excuse the verbosity. OJ says it fails for a case (a long one which I won't copy and paste here to avoid clutter). For some reason, when I click "Submit Solution" the output is missing (3,27) but gets all the other pairs correct. What's weird is that when I use the "Run Code" option, (3,27) shows up correctly in the output, This is such a weird bug for me as there doesn't seem to be anything special about (3,27) as far as I can tell. Can someone help me?


Log in to reply
 

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