Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- knakul853
- */
- class Solution {
- public:
- ListNode* partition(ListNode* head, int x) {
- ListNode* p1 = new ListNode();
- ListNode* p2 = new ListNode();
- ListNode* tempP1 = p1;
- ListNode* tempP2 = p2;
- while( head )
- {
- if( head->val < x )
- {
- p1->next = new ListNode( head->val );
- p1 = p1->next;
- }
- else{
- p2->next = new ListNode( head->val );
- p2 = p2->next;
- }
- head = head->next;
- }
- p2->next = NULL;
- p1->next = tempP2->next;
- return tempP1->next;
- }
- };
Add Comment
Please, Sign In to add comment