Skip to content

Commit 31da636

Browse files
committed
LoopInLinkedList: make comparison with null earlier
1 parent 7ec67a4 commit 31da636

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/main/java/by/andd3dfx/collections/LoopInLinkedList.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ public static boolean isPresent(Node head) {
2727

2828
while (true) {
2929
fast = fast.next;
30-
if (fast == slow) {
31-
return true;
32-
}
3330
if (fast == null) {
3431
return false;
3532
}
36-
37-
slow = slow.next;
38-
fast = fast.next;
3933
if (fast == slow) {
4034
return true;
4135
}
36+
37+
slow = slow.next;
38+
fast = fast.next;
4239
if (fast == null) {
4340
return false;
4441
}
42+
if (fast == slow) {
43+
return true;
44+
}
4545
}
4646
}
4747
}

0 commit comments

Comments
 (0)