From 5955c1de5dc8811b30c29c49121cb8ad42ff32c4 Mon Sep 17 00:00:00 2001 From: yawebNW <38253154+yawebNW@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:48:33 +0800 Subject: [PATCH] =?UTF-8?q?Update=200332.=E9=87=8D=E6=96=B0=E5=AE=89?= =?UTF-8?q?=E6=8E=92=E8=A1=8C=E7=A8=8B.md=20=E6=9B=B4=E6=96=B0java?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit java最后一个方法新增去重逻辑,原代码遇到循环时会无限递归 --- problems/0332.重新安排行程.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/problems/0332.重新安排行程.md b/problems/0332.重新安排行程.md index 144672a9..bc453c51 100644 --- a/problems/0332.重新安排行程.md +++ b/problems/0332.重新安排行程.md @@ -379,6 +379,8 @@ class Solution { String targetLocation; //遍历从当前位置出发的机票 for (int i = 0; i < targetLocations.size(); i++) { + //去重,否则在最后一个测试用例中遇到循环时会无限递归 + if(i > 0 && targetLocations.get(i).equals(targetLocations.get(i - 1))) continue; targetLocation = targetLocations.get(i); //删除终点列表中当前的终点 targetLocations.remove(i);