Skip to content

Commit

Permalink
148
Browse files Browse the repository at this point in the history
  • Loading branch information
lzl124631x committed Feb 24, 2022
1 parent 0ddad01 commit c7bbec0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions leetcode/148. Sort List/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// Time: O(NlogN)
// Space: O(logN)
class Solution {
pair<ListNode*, ListNode*> splitList(ListNode *head) {
ListNode* splitList(ListNode *head) {
ListNode dummy, *p = &dummy, *q = &dummy;
dummy.next = head;
while (q && q->next) {
Expand All @@ -60,7 +60,7 @@ class Solution {
}
auto next = p->next;
p->next = NULL;
return {head, next};
return next;
}
ListNode *mergeList(ListNode *a, ListNode *b) {
ListNode head, *tail = &head;
Expand All @@ -83,8 +83,8 @@ class Solution {
public:
ListNode* sortList(ListNode* head) {
if (!head || !head->next) return head;
auto [a, b] = splitList(head);
return mergeList(sortList(a), sortList(b));
auto b = splitList(head);
return mergeList(sortList(head), sortList(b));
}
};
```
Expand Down

0 comments on commit c7bbec0

Please sign in to comment.