Skip to content

Commit 47f434a

Browse files
authored
Update shortest-path-in-a-grid-with-obstacles-elimination.py
1 parent 9af7a74 commit 47f434a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Python/shortest-path-in-a-grid-with-obstacles-elimination.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ def a_star(grid, b, t, k):
2525
f += dh
2626
closer, detour = detour, closer
2727
b, k = closer.pop()
28+
if b == t:
29+
return f
2830
if b in lookup and lookup[b] >= k:
2931
continue
3032
lookup[b] = k
31-
if b == t:
32-
return f
3333
for dx, dy in directions:
3434
nb = (b[0]+dx, b[1]+dy)
3535
if not (0 <= nb[0] < len(grid) and 0 <= nb[1] < len(grid[0]) and

0 commit comments

Comments
 (0)