---
# System prepended metadata

title: 148. Sort List
tags: [leetcode]

---

# 148. Sort List
[TOC]
## Run Code
![](https://i.imgur.com/SjmWGde.png)

## 題意
從小排到大，資料結構為Linked List
## 解題思路
sort
## 困難之處
nope
## Code
```cpp=
class Solution {
public:
    ListNode* sortList(ListNode* head) {
        multiset<int> hash;
        for(ListNode *ptr = head;ptr!=NULL;ptr = ptr->next){
            hash.insert(ptr->val);
        }
        multiset<int>::iterator it = hash.begin();
        for(ListNode *ptr = head; ptr!=nullptr;ptr=ptr->next){
            ptr->val = *it;
            it++;
        }
        return head;
    }
};
```

###### tags: `leetcode`