Skip to content

Commit 44957b7

Browse files
author
Joseph Luce
authored
Update shortest_distance_from_all_buildings.md
1 parent af959fa commit 44957b7

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

real_interview_questions/Google/shortest_distance_from_all_buildings.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ class Solution(object):
5656
visited_set.add(start_indexes)
5757
distance = result = 0
5858
total_n_buildings_found = 0
59+
memo = dict()
5960
6061
while len(bfs_queue) != 0 and total_n_buildings_found < n_buildings:
6162
n_pops = len(bfs_queue)
6263
distance += 1
63-
n_buildings_found = 0
6464
while n_pops > 0:
6565
curr_indexes = bfs_queue.pop()
6666
n_pops -= 1
@@ -72,11 +72,8 @@ class Solution(object):
7272
if element == 0:
7373
bfs_queue.appendleft(neighbor)
7474
elif element == 1:
75-
n_buildings_found += 1
75+
result += distance
7676
total_n_buildings_found += 1
77-
if n_buildings_found != 0:
78-
result += (distance * n_buildings_found)
79-
n_buildings_found = 0
8077
if total_n_buildings_found != n_buildings:
8178
return -1
8279
return result

0 commit comments

Comments
 (0)