Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cda0e0d

Browse files
authoredOct 16, 2020
Update and rename 86. Partition List.cpp to 086.Partition-List_v1.cpp
1 parent 687c04e commit cda0e0d

File tree

2 files changed

+36
-43
lines changed

2 files changed

+36
-43
lines changed
 
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* ListNode *next;
6+
* ListNode(int x) : val(x), next(NULL) {}
7+
* };
8+
*/
9+
class Solution {
10+
public:
11+
ListNode* partition(ListNode* head, int x)
12+
{
13+
ListNode* h1 = new ListNode(0);
14+
ListNode* h2 = new ListNode(0);
15+
ListNode* p = h1;
16+
ListNode* q = h2;
17+
18+
while (head!=NULL)
19+
{
20+
if (head->val<x)
21+
{
22+
p->next = head;
23+
p = p->next;
24+
}
25+
else
26+
{
27+
q->next= head;
28+
q = q->next;
29+
}
30+
head = head->next;
31+
}
32+
p->next = h2->next;
33+
q->next = NULL;
34+
return h1->next;
35+
}
36+
};

‎Linked_List/086.Partition-List/86. Partition List.cpp

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.