# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

#
# 
# @param head ListNode类 
# @return ListNode类
#
class Solution:
    def sortList(self , head ):
        # write code here
        a = []
        cur = head
        while head is not None:
            a.append(head.val)
            head = head.next
        if len(a) < 2:
            return cur
        a.sort()
        tep = ListNode(a[-1])
        for ik in range(len(a)-2, -1, -1):
            res = ListNode(a[ik])
            res.next = tep
            tep = res
            
        return res