Compiling wrong answer but getting correct ans using ideone


#1

could not upload image of submission in ideone…plz check it once.
class Solution:
# @param A : integer
# @param B : integer
# @param C : integer
# @param D : integer
# @param E : integer
# @param F : integer
# @return an integer
def recur(self,dp,i,j,m,n,N,M,X,Y,visit):
if i==m and j==n:
return 0
elif i<0 or j<0 or i>=N or j>=M:
return float(‘inf’)
elif dp[i][j]!=0:
return dp[i][j]
elif visit[i][j]==1:
return float(‘inf’)
else:
visit[i][j] = 1
a = float(‘inf’)
for k in range(len(X)):
a = min(a,self.recur(dp,i+X[k],j+Y[k],m,n,N,M,X,Y,visit)+1)
dp[i][j]=a
return dp[i][j]

def knight(self, N,M, x1, y1, x2, y2):
    i,j,m,n = x1,y1,x2,y2
    dp =[[0 for _ in range(M+1)]for j in range(N+1)]
    visit = [[0 for _ in range(M+1)]for j in range(N+1)]
    X  = [2,2,1,-1,-2,-2,-1,1]
    Y = [1,-1,-2,-2,-1,1,2,2]
    a = self.recur(dp,i,j,m,n,N,M,X,Y,visit)
    return -1 if a==float('inf') else a