diff options
Diffstat (limited to 'other/partition_list.cpp')
-rw-r--r-- | other/partition_list.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/other/partition_list.cpp b/other/partition_list.cpp new file mode 100644 index 0000000..b2e44a9 --- /dev/null +++ b/other/partition_list.cpp @@ -0,0 +1,20 @@ +#include "leetcode.h" + +class Solution { +public: + ListNode *partition(ListNode *head, int x) { + ListNode *fTmp = new ListNode(0), *bTmp = new ListNode(0), *front = fTmp, + *back = bTmp, *curr = head; + while (curr) { + if (curr->val < x) { + front->next = curr; + front = curr; + } else { + back->next = curr; + back = curr; + } + } + front->next = bTmp->next, back->next = nullptr; + return fTmp->next; + } +}; |