Merge pull request #853 from Jerry-306/patch-40

改进 0143 重排链表
This commit is contained in:
程序员Carl
2021-10-18 10:11:31 +08:00
committed by GitHub

View File

@ -50,10 +50,6 @@ public:
cur = cur->next; cur = cur->next;
count++; count++;
} }
if (vec.size() % 2 == 0) { // 如果是偶数,还要多处理中间的一个
cur->next = vec[i];
cur = cur->next;
}
cur->next = nullptr; // 注意结尾 cur->next = nullptr; // 注意结尾
} }
}; };
@ -249,12 +245,6 @@ public class ReorderList {
cur = cur.next; cur = cur.next;
count++; count++;
} }
// 当是偶数的话,需要做额外处理
if (list.size() % 2== 0){
cur.next = list.get(l);
cur = cur.next;
}
// 注意结尾要结束一波 // 注意结尾要结束一波
cur.next = null; cur.next = null;
} }
@ -376,11 +366,6 @@ var reorderList = function(head, s = [], tmp) {
cur = cur.next; cur = cur.next;
count++; count++;
} }
// 当是偶数的话,需要做额外处理
if(list.length % 2 == 0){
cur.next = list[l];
cur = cur.next;
}
// 注意结尾要结束一波 // 注意结尾要结束一波
cur.next = null; cur.next = null;
} }