题解 | #单链表的排序#
单链表的排序
https://www.nowcoder.com/practice/f23604257af94d939848729b1a5cda08
func sortInList( head *ListNode ) *ListNode { // write code here var mm = make([]*ListNode, 0) P := head for P!=nil { mm = append(mm, P) P = P.Next } sort.Slice(mm, func(i , j int) bool { return mm[i].Val < mm[j].Val }) node := &ListNode{} p := node for _ ,v := range mm{ p.Next = v p = v } p.Next = nil return node.Next }