Published:
Updated:

  • 파이썬 TeamSort λ‚΄μž₯ ν•¨μˆ˜(sort())λ₯Ό μ΄μš©ν•˜μ—¬ ν’‚
    • μžλ°”μ—μ„œλ„ Collectionsλ₯Ό μ΄μš©ν•˜λ©΄ Teamsort μ‚¬μš© κ°€λŠ₯


SolutionPermalink

# Definition for singly-linked list.
from typing import Optional


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


class Solution:
    def sortList(self, head: Optional[ListNode]) -> Optional[ListNode]:
        arr = []
        linked_to = head
        while linked_to:
            arr.append(linked_to.val)
            linked_to = linked_to.next

        arr.sort()

        linked_from = head
        for x in arr:
            linked_from.val = x
            linked_from = linked_from.next

        return head


ReferencePermalink

Leave a comment