[yuseok89] WEEK 09 Solutions - #2824
Open
yuseok89 wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
🏷️ 알고리즘 패턴 분석
linked-list-cycle/yuseok89.py
# TC: O(N)
# SC: O(1)
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def hasCycle(self, head: Optional[ListNode]) -> bool:
if not head or not head.next:
return False
slow, fast = head, head.next
while slow != fast:
if not fast or not fast.next:
return False
slow, fast = slow.next, fast.next.next
return True
- 패턴: Two Pointers, Fast & Slow Pointers
- 설명: 해당 코드는 느린 포인터와 빠른 포인터를 이용해 순환 여부를 판별하는 전형적인 Fast & Slow Pointers 패턴이다. 두 포인터의 속도 차이를 이용해 사이클 존재 여부를 O(N) 시간, O(1) 공간으로 판단한다.
📊 시간/공간 복잡도 분석
| 복잡도 | |
|---|---|
| Time | O(n) |
| Space | O(1) |
피드백: 빠른 포인터와 느린 포인터를 이용해 순회하므로 추가 메모리 없이 사이클 여부를 판단할 수 있다.
개선 제안: 현재 구현이 적절해 보입니다.
💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!
Contributor
📊 yuseok89 님의 학습 현황이번 주 제출 문제
누적 학습 요약
문제 풀이 현황
🤖 이 댓글은 GitHub App을 통해 자동으로 작성되었습니다. 🔢 API 사용량 (gpt-5-nano)
|
Contributor
There was a problem hiding this comment.
조건문 부분에 같은지 비교를 하는것도 꽤 괜찮은 아이디어시네요!
다만 아주 개인적인 의견인데, slow와 fast를 비교하는것은 참조를 비교하는거라 is를 쓰는게 더 낫지 않을까? 하는 생각이 있었어요
좋은 코드 보고 갑니다!
DaleSeo
self-requested a review
August 20, 2026 03:15
DaleSeo
approved these changes
Aug 20, 2026
Comment on lines
+11
to
+12
| if not head or not head.next: | ||
| return False |
Member
There was a problem hiding this comment.
노드가 하나뿐이고 순환이 없는 입력이라면 fast가 None으로 시작하므로, 반복문 안의 if not fast 가 곧바로 False를 반환해 줄텐데요. 그렇다면 여기서 not head.next까지 확인하는 것은 어떤 경우를 대응하기 위한 목적인가요?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!