linkedlist

λ§ν¬λ“œλ¦¬μŠ€νŠΈμ— 사이클이 μžˆλŠ”μ§€ μ—†λŠ”μ§€ νŒλ‹¨ν•˜λŠ” λ¬Έμ œμ΄λ‹€.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: ..
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 # λ‹€..
yesolz
'linkedlist' νƒœκ·Έμ˜ κΈ€ λͺ©λ‘