일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 생성형AI
- 파이썬알고리즘
- LeetCode
- 코드업
- GenerativeAI
- codeup
- 릿코드
- sql코테
- Python3
- slidingwindow
- Greedy
- 리트코드
- 니트코드
- Python
- tree
- Stack
- nlp
- stratascratch
- SQL
- 알고리즘
- two-pointer
- 파이썬기초100제
- 파이썬
- dfs
- GenAI
- heap
- array
- Recursion
- 투포인터
- 슬라이딩윈도우
Archives
- Today
- Total
Tech for good
[Neetcode/Linked Lists] Linked List Cycle Detection 본문
IT/Computer Science
[Neetcode/Linked Lists] Linked List Cycle Detection
Diana Kang 2025. 7. 2. 06:12# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def hasCycle(self, head: Optional[ListNode]) -> bool:
passed = set()
current = head
while current:
if current in passed:
return True
passed.add(current)
current = current.next
return False
- list
- when you know the length -> for loop
- listed list
- sequence is important! 0 -> 1 -> 2 -> 3
- while loop (since the length is not important)
'IT > Computer Science' 카테고리의 다른 글
[Leetcode/Linked List, Two Pointers] 876. Middle of the Linked List (0) | 2025.07.09 |
---|---|
[Neetcode/Linked Lists] Intersection of Two Linked Lists (0) | 2025.07.03 |
[Neetcode/Array, Hash Table] Group Anagrams (0) | 2025.07.01 |
[Neetcode/Stack] Daily Temperatures (0) | 2025.06.28 |
[Neetcode/Stack] Minimum Stack (0) | 2025.06.28 |