λ§ν¬λ리μ€νΈμ μ¬μ΄ν΄μ΄ μλμ§ μλμ§ νλ¨νλ λ¬Έμ μ΄λ€.setμ μ΄μ©νμ¬ κ°λ¨ν ν μλ μμ§λ§, νλ‘μ΄λμ μν μ°ΎκΈ° μκ³ λ¦¬μ¦, νλ‘μ΄λμ ν λΌμ κ±°λΆμ΄ μκ³ λ¦¬μ¦μΌλ‘λ ν μ μλ μ¬λ°λ λ¬Έμ μλ€! νμ΄1. set μ΄μ©# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def hasCycle(self, head: Optional[ListNode]) -> bool: seen = set() cur = head while cur: ..
linkedlist
You are given the heads of two sorted linked lists list1 and list2.Merge the two lists into one sorted list. The list should be made by splicing together the nodes of the first two lists.Return the head of the merged linked list.λ κ°μ λ§ν¬λ리μ€νΈλ₯Ό νλμ sorted linked listλ‘ λ§λ€κΈ°! νμ΄1: Recursion (μ¬κ·)# Definition for singly-linked list.# class ListNode:# def __init__(self, val=0, next=None):# se..
Given head, the head of a linked list, determine if the linked list has a cycle in it.There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter.Return true if there is a cycle i..
Given the head of a singly linked list, reverse the list, and return the reversed list.singly linked list κ° μ£Όμ΄μ§λ©΄, reversed listλ₯Ό λ°ννλ λ¬Έμ λ€. ListNode ν΄λμ€νμ΄μ¬μμ μ°κ²°λ¦¬μ€νΈλ₯Ό ꡬννκΈ° μν΄μλ μ§μ ν΄λμ€λ₯Ό μ μν΄μΌ νλ€.LeetCode λ¬Έμ μμ μ 곡λλ μ°κ²° 리μ€νΈ μ μλ λ€μκ³Ό κ°λ€.# Definition for singly-linked list.# class ListNode:# def __init__(self, val=0, next=None):# self.val = val # νμ¬ λ
Έλκ° μ μ₯νλ κ°# self.next = next # λ€..