leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0086.cpp (462B)


0 class Solution {
1 public:
2 ListNode *partition(ListNode *head, int x) {
3 ListNode hless, hmore;
4 ListNode *less = &hless, *more = &hmore;
6 for (ListNode *crnt = head; crnt; crnt = crnt->next) {
7 if (crnt->val < x)
8 less = less->next = crnt;
9 else
10 more = more->next = crnt;
11 }
13 less->next = hmore.next;
14 more->next = nullptr;
15 return hless.next;
16 }
17 };