# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def sortList(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        list1=[]
        while head!=None:
            list1.append(head.val)
            head=head.next
        list1.sort()
        if len(list1)==0:
            return None
        pre=cur=ListNode(-1)
        for i in range(len(list1)):
            current=ListNode(list1[i])
            cur.next=current
            cur=current
        cur.next=None
        return pre.next
s1 = "leetcode"
wordDict = ["leet", "code"]
s=Solution()
print(s.wordBreak(s1,wordDict))