Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f1f673d

Browse files
✨update: Modify 815
1 parent 81d6690 commit f1f673d

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

‎LeetCode/811-820/815. 公交路线(困难).md‎

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,23 +212,25 @@ class Solution {
212212
return 0x3f3f3f3f; // never
213213
}
214214
int update(Deque<Integer> d, Map<Integer, Integer> cur, Map<Integer, Integer> other) {
215-
// 取出当前所在的路线,与进入该路线所花费的距离
216-
int poll = d.pollFirst();
217-
int step = cur.get(poll);
218-
219-
// 遍历该路线所包含的车站
220-
for (int station : rs[poll]) {
221-
// 遍历将由该线路的车站发起的路线
222-
Set<Integer> lines = map.get(station);
223-
if (lines == null) continue;
224-
for (int nr : lines) {
225-
if (cur.containsKey(nr)) continue;
226-
if (other.containsKey(nr)) return step + other.get(nr);
227-
cur.put(nr, step + 1);
228-
d.add(nr);
215+
int m = d.size();
216+
while (m-- > 0) {
217+
// 取出当前所在的路线,与进入该路线所花费的距离
218+
int poll = d.pollFirst();
219+
int step = cur.get(poll);
220+
221+
// 遍历该路线所包含的车站
222+
for (int station : rs[poll]) {
223+
// 遍历将由该线路的车站发起的路线
224+
Set<Integer> lines = map.get(station);
225+
if (lines == null) continue;
226+
for (int nr : lines) {
227+
if (cur.containsKey(nr)) continue;
228+
if (other.containsKey(nr)) return step + other.get(nr);
229+
cur.put(nr, step + 1);
230+
d.add(nr);
231+
}
229232
}
230233
}
231-
232234
return -1;
233235
}
234236
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /