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 5955c1d

Browse files
authored
Update 0332.重新安排行程.md 更新java版本
java最后一个方法新增去重逻辑,原代码遇到循环时会无限递归
1 parent 7c5e1c5 commit 5955c1d

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

‎problems/0332.重新安排行程.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ class Solution {
379379
String targetLocation;
380380
//遍历从当前位置出发的机票
381381
for (int i = 0; i < targetLocations.size(); i++) {
382+
//去重,否则在最后一个测试用例中遇到循环时会无限递归
383+
if(i > 0 && targetLocations.get(i).equals(targetLocations.get(i - 1))) continue;
382384
targetLocation = targetLocations.get(i);
383385
//删除终点列表中当前的终点
384386
targetLocations.remove(i);

0 commit comments

Comments
(0)

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