class Solution {
public:
    ListNode* insertionSortList(ListNode* head) {
        ListNode *dummy = new ListNode(-1), *cur = dummy;
        while (head) {
            ListNode *t = head->next;
            cur = dummy;
            while (cur->next && cur->next->val <= head->val) {
                cur = cur->next;
            }
            head->next = cur->next;
            cur->next = head;
            head = t;
        }
        return dummy->next;
    }
};

相关文章:

  • 2021-06-15
  • 2021-08-24
  • 2021-10-18
  • 2022-02-05
  • 2022-01-14
  • 2022-01-15
  • 2021-06-01
  • 2022-12-23
猜你喜欢
  • 2021-08-01
  • 2021-10-03
相关资源
相似解决方案