Skip to content

Commit 77d3469

Browse files
authored
改进 0143 重排链表
在使用数组存储链表节点的写法中,最后再判断数组长度为偶数时时没有必要的,因为在循环体while里面,我们用的是 i<=j。
1 parent f88678d commit 77d3469

File tree

1 file changed

+0
-15
lines changed

1 file changed

+0
-15
lines changed

problems/0143.重排链表.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ public:
5050
cur = cur->next;
5151
count++;
5252
}
53-
if (vec.size() % 2 == 0) { // 如果是偶数,还要多处理中间的一个
54-
cur->next = vec[i];
55-
cur = cur->next;
56-
}
5753
cur->next = nullptr; // 注意结尾
5854
}
5955
};
@@ -249,12 +245,6 @@ public class ReorderList {
249245
cur = cur.next;
250246
count++;
251247
}
252-
// 当是偶数的话,需要做额外处理
253-
if (list.size() % 2== 0){
254-
cur.next = list.get(l);
255-
cur = cur.next;
256-
}
257-
258248
// 注意结尾要结束一波
259249
cur.next = null;
260250
}
@@ -376,11 +366,6 @@ var reorderList = function(head, s = [], tmp) {
376366
cur = cur.next;
377367
count++;
378368
}
379-
// 当是偶数的话,需要做额外处理
380-
if(list.length % 2 == 0){
381-
cur.next = list[l];
382-
cur = cur.next;
383-
}
384369
// 注意结尾要结束一波
385370
cur.next = null;
386371
}

0 commit comments

Comments
 (0)