From 77d346988b1718b34f4997e7d08be82c418edd6b Mon Sep 17 00:00:00 2001 From: Luo <82520819+Jerry-306@users.noreply.github.com> Date: Fri, 15 Oct 2021 20:16:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=200143=20=E9=87=8D=E6=8E=92?= =?UTF-8?q?=E9=93=BE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在使用数组存储链表节点的写法中,最后再判断数组长度为偶数时时没有必要的,因为在循环体while里面,我们用的是 i<=j。 --- problems/0143.重排链表.md | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/problems/0143.重排链表.md b/problems/0143.重排链表.md index c5ac9bae..a6412d2e 100644 --- a/problems/0143.重排链表.md +++ b/problems/0143.重排链表.md @@ -50,10 +50,6 @@ public: cur = cur->next; count++; } - if (vec.size() % 2 == 0) { // 如果是偶数,还要多处理中间的一个 - cur->next = vec[i]; - cur = cur->next; - } cur->next = nullptr; // 注意结尾 } }; @@ -249,12 +245,6 @@ public class ReorderList { cur = cur.next; count++; } - // 当是偶数的话,需要做额外处理 - if (list.size() % 2== 0){ - cur.next = list.get(l); - cur = cur.next; - } - // 注意结尾要结束一波 cur.next = null; } @@ -376,11 +366,6 @@ var reorderList = function(head, s = [], tmp) { cur = cur.next; count++; } - // 当是偶数的话,需要做额外处理 - if(list.length % 2 == 0){ - cur.next = list[l]; - cur = cur.next; - } // 注意结尾要结束一波 cur.next = null; }