/**

  • struct ListNode {
  • int val;
  • struct ListNode *next;
  • }; */

class Solution { public: /** * * @param head ListNode类 the head node * @return ListNode类 / vector res; ListNode sortInList(ListNode* head) { // write code here if(!head) return nullptr; auto p1 = head; while(p1) { res.push_back(p1 -> val); p1 = p1 -> next; } sort(res.begin(), res.end()); auto p2 = head; for(int i = 0; i < res.size(); i ++ ) { p2 -> val = res[i]; p2 = p2 -> next; } return head; } };