Skip to content

Commit a7f9a2d

Browse files
committed
Runtime 428 ms (Top 78.39%) | Memory 46.0 MB (Top 5.2%)
1 parent 373f565 commit a7f9a2d

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed
+14-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
class Solution:
22
def sortList(self, head: Optional[ListNode]) -> Optional[ListNode]:
3-
temp = ListNode()
4-
sort = temp
5-
val = []
6-
while head:
7-
val.append(head.val)
8-
head = head.next
9-
val = sorted(val)
10-
for i in val:
11-
curr = ListNode(i)
12-
sort.next = curr
13-
sort = sort.next
14-
return temp.next
15-
3+
store = []
4+
curr = head
5+
while curr:
6+
store.append(curr.val)
7+
curr = curr.next
8+
store.sort()
9+
dummyNode = ListNode(0)
10+
temp = dummyNode
11+
12+
for i in store:
13+
x = ListNode(val = i)
14+
temp.next = x
15+
temp = x
16+
return dummyNode.next

0 commit comments

Comments
 (0)