Skip to content

[yuseok89] WEEK 09 Solutions - #2824

Open
yuseok89 wants to merge 1 commit into
DaleStudy:mainfrom
yuseok89:main
Open

[yuseok89] WEEK 09 Solutions#2824
yuseok89 wants to merge 1 commit into
DaleStudy:mainfrom
yuseok89:main

Conversation

@yuseok89

@yuseok89 yuseok89 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

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)

피드백: 빠른 포인터와 느린 포인터를 이용해 순회하므로 추가 메모리 없이 사이클 여부를 판단할 수 있다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

@dalestudy

dalestudy Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

📊 yuseok89 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
linked-list-cycle Easy ✅ 의도한 유형

누적 학습 요약

  • 풀이한 문제: 39 / 75개
  • 이번 주 유형 일치율: 100% (1문제 중 1문제 일치)

문제 풀이 현황

카테고리 진행도 완료
Dynamic Programming ■■■■■■□ 9 / 11 (Easy 1, Medium 8)
Array ■■■■■■□ 8 / 10 (Medium 5, Easy 3)
Matrix ■■■■■□□ 3 / 4 (Medium 3)
String ■■■■■□□ 7 / 10 (Medium 4, Easy 3)
Binary ■■■□□□□ 2 / 5 (Easy 2)
Graph ■■■□□□□ 3 / 8 (Medium 3)
Linked List ■■□□□□□ 2 / 6 (Easy 2)
Heap ■■□□□□□ 1 / 3 (Medium 1)
Tree ■■□□□□□ 4 / 14 (Medium 3, Easy 1)
Interval □□□□□□□ 0 / 5 ← 아직 시작 안 함

🤖 이 댓글은 GitHub App을 통해 자동으로 작성되었습니다.

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 340 50 390 $0.000037
2 340 53 393 $0.000038
합계 680 103 783 $0.000075

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

조건문 부분에 같은지 비교를 하는것도 꽤 괜찮은 아이디어시네요!
다만 아주 개인적인 의견인데, slow와 fast를 비교하는것은 참조를 비교하는거라 is를 쓰는게 더 낫지 않을까? 하는 생각이 있었어요
좋은 코드 보고 갑니다!

@DaleSeo
DaleSeo self-requested a review August 20, 2026 03:15

@DaleSeo DaleSeo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!

Comment on lines +11 to +12
if not head or not head.next:
return False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

노드가 하나뿐이고 순환이 없는 입력이라면 fastNone으로 시작하므로, 반복문 안의 if not fast 가 곧바로 False를 반환해 줄텐데요. 그렇다면 여기서 not head.next까지 확인하는 것은 어떤 경우를 대응하기 위한 목적인가요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Solving

Development

Successfully merging this pull request may close these issues.

3 participants