File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Floyd tortoise and hare ์๊ณ ๋ฆฌ์ฆ์ ๋ฐํ์ผ๋ก
3+ * ํ์นธ์ฉ ์ด๋ํ๋ ํฌ์ธํฐ์ 2์นธ์ฉ ์ด๋ํ๋ ํฌ์ธํฐ๋ ๊ฒฐ๊ตญ์ ๋ง๋๋ค๋ ์ ์ ์ด์ฉํด์ ํ
4+ *
5+ * TC: O(N)
6+ * SC: O(1)
7+ * N: linked list length
8+ */
9+
10+ /**
11+ * Definition for singly-linked list.
12+ * function ListNode(val) {
13+ * this.val = val;
14+ * this.next = null;
15+ * }
16+ */
17+
18+ /**
19+ * @param {ListNode } head
20+ * @return {boolean }
21+ */
22+ var hasCycle = function ( head ) {
23+ let oneStep = head ;
24+ let twoStep = head ;
25+
26+ while ( twoStep && twoStep . next ) {
27+ if ( oneStep === twoStep ) {
28+ return true ;
29+ }
30+
31+ oneStep = oneStep . next ;
32+ twoStep = twoStep . next . next ;
33+ }
34+
35+ return false ;
36+ } ;
You canโt perform that action at this time.
0 commit comments