Skip to content

Commit ebb3b54

Browse files
committed
issue #10 141-Done
1 parent 93b196e commit ebb3b54

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎src/leetcodeEasyLevel/_0141/LinkedListCycle.java‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,27 @@
22

33
public class LinkedListCycle {
44

5-
public boolean hasCycle(ListNode head) {
5+
public static boolean hasCycle(ListNode head) {
6+
//엣지케이스
7+
if (head == null) {
8+
return false;
9+
}
10+
//slow는 한 칸씩 이동
11+
//fast는 두 칸씩 이동
12+
ListNode slow = head;
13+
ListNode fast = head.next;
614

15+
while (fast != null && fast.next != null) {
16+
slow = slow.next;
17+
fast = fast.next.next;
18+
// 포인터끼리 만나면 true
19+
if (fast == slow) {
20+
return true;
21+
}
22+
}
23+
return false;
724
}
25+
826
}
927

1028
class ListNode {

0 commit comments

Comments
 (0)