반응형
leetcode.com/problems/insertion-sort-list/
풀긴 하였지만 소요 시간이 매우 길다..
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def insertionSortList(self, head: ListNode) -> ListNode:
root = node = ListNode(None)
while head:
node = root
while node.next and node.next.val < head.val:
node = node.next
node.next = ListNode(head.val,node.next)
head = head.next
return root.next
댓글