Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit730a68b

Browse files
authored
Merge pull requestneetcode-gh#311 from SharmaTushar1/patch-8
Create 141. Linked List Cycle.java
2 parentsbfe8be4 +333536e commit730a68b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎java/141. Linked List Cycle.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//Fast and slow pointer
2+
3+
publicclassSolution {
4+
publicbooleanhasCycle(ListNodehead) {
5+
ListNodefast =head;
6+
ListNodeslow =head;
7+
while (fast!=null &&fast.next!=null) {
8+
fast =fast.next.next;
9+
slow =slow.next;
10+
if (fast ==slow)returntrue;
11+
}
12+
returnfalse;
13+
}
14+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp