-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortList.py
More file actions
28 lines (26 loc) · 777 Bytes
/
sortList.py
File metadata and controls
28 lines (26 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution(object):
def sortList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
temp =[];
current = head
if head is not None:
while current:
temp.append(current.val)
current = current.next;
temp.sort();
i=0;
head= ListNode(temp[0]);
current = head;
for i in range(1,len(temp), +1):
current.next = ListNode(temp[i]);
current = current.next;
i+=1;
return head;