Skip to content

Commit

Permalink
refactor: azl397985856#86 重构代码
Browse files Browse the repository at this point in the history
  • Loading branch information
luzhipeng committed May 23, 2019
1 parent 71c42fa commit 1df79cd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions problems/86.partition-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Output: 1->2->2->4->3->5

## 思路

- 设定两个虚拟节点,dummyHead1用来保存小于于该值的链表,dummyHead2来保存大于等于该值的链表
- 设定两个虚拟节点,dummyHead1用来保存小于该值的链表,dummyHead2来保存大于等于该值的链表

- 遍历整个原始链表,将小于该值的放于dummyHead1中,其余的放置在dummyHead2中

Expand Down Expand Up @@ -89,7 +89,7 @@ var partition = function(head, x) {
let currentL2 = dummyHead2;
while(current.next) {
current = current.next;
if (current.val >= x) {
if (current.val < x) {
currentL1.next = current;
currentL1 = current;
} else {
Expand All @@ -98,10 +98,10 @@ var partition = function(head, x) {
}
}

currentL1.next = null;
currentL2.next = null;

currentL2.next = dummyHead1.next;
currentL1.next = dummyHead2.next;

return dummyHead2.next;
return dummyHead1.next;
};
```

0 comments on commit 1df79cd

Please sign in to comment.