[leetcode]partition-list 分隔链表

avatar
作者
猴君
阅读量:2

. - 力扣(LeetCode)

class Solution { public:     ListNode* partition(ListNode* head, int x) {         ListNode *smlDummy = new ListNode(0), *bigDummy = new ListNode(0);         ListNode *sml = smlDummy, *big = bigDummy;         while (head != nullptr) {             if (head->val < x) {                 sml->next = head;                 sml = sml->next;             } else {                 big->next = head;                 big = big->next;             }             head = head->next;         }         sml->next = bigDummy->next;         big->next = nullptr;         return smlDummy->next;     } };  

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!