Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions linked-list-cycle/sangbeenmoon.py
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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Fast & Slow Pointers
  • 설명: 이 코드는 순환 여부를 판단하기 위해 포인터를 한 번씩 이동시키며 순환이 존재하는지 체크하는 패턴으로, Fast & Slow Pointers 기법과 유사합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(1)

피드백: 노드 방문 여부를 기록하는 대신 방문 횟수 제한을 통해 사이클을 감지하는 방법으로, 최악의 경우 리스트 길이만큼 순회하며 시간 복잡도는 선형입니다. 공간은 상수입니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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:
MM = 10001
Copy link
Copy Markdown
Contributor

@liza0525 liza0525 May 1, 2026

Choose a reason for hiding this comment

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

문제 조건에 node의 개수가 최대 10000개라고 되어 있어서 이렇게 풀이도 가능하군요👀
저는 놓쳤던 조건인데, 덕분에 한 번 더 확인하게 되었습니다!

cnt = 0
cur = head
while cur:
cnt += 1
if cnt > MM:
return True
cur = cur.next

return False
Loading