We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent df919d5 commit 8089c42Copy full SHA for 8089c42
โlinked-list-cycle/Chaedie.py
@@ -0,0 +1,24 @@
1
+"""
2
+Solution:
3
+ 1) ์ฌ์ดํด์ด ์๋ค๋ฉด ๋ฌดํ ๋ฃจํ๊ฐ ๋ฐ์ํ ๊ฒ์ด๋ค.
4
+ 2) ์ฌ์ดํด์ด ์๋ค๋ฉด ์ธ์ ๊ฐ null ์ด ๋ ๊ฒ์ด๋ค.
5
+ 3) ๋ฐ๋ผ์ ๋๊ฐ์ ํฌ์ธํฐ๋ฅผ ์ฌ์ฉํ์ฌ ๋์ผํ Node์ ๋๋ฌํ๋ ์ง ํ์ธํ๋ค.
6
+ 4) null ์ด ๋๋ค๋ฉด ์ฌ์ดํด์ด ์๋ค๋ ๋ป์ด๋ค.
7
+Time: O(n)
8
+Space: O(1)
9
10
+
11
12
+class Solution:
13
+ def hasCycle(self, head: Optional[ListNode]) -> bool:
14
+ if not head or not head.next:
15
+ return False
16
17
+ slow = head
18
+ fast = head.next
19
+ while slow and fast and fast.next:
20
+ slow = slow.next
21
+ fast = fast.next.next
22
+ if slow == fast:
23
+ return True
24
0 commit comments