We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8198861 commit f46c847Copy full SHA for f46c847
1 file changed
swordoffer/EntryNodeOfListSolution.java
@@ -0,0 +1,43 @@
1
+/**
2
+ * 剑指Offer,链表中环的入口点
3
+ */
4
+
5
6
7
+public class ListNode {
8
+ int val;
9
+ ListNode next = null;
10
11
+ ListNode(int val) {
12
+ this.val = val;
13
+ }
14
+}
15
16
+ public class EntryNodeOfListSolution {
17
18
+ public ListNode EntryNodeOfLoop(ListNode pHead)
19
+ {
20
+ ListNode slow = pHead;
21
+ ListNode fast = pHead;
22
23
+ while(fast != null && fast.next != null) {
24
+ slow = slow.next;
25
+ fast = fast.next.next;
26
+ if ( slow == fast ) {
27
+ break;
28
29
30
31
+ if (fast == null || fast.next == null) {
32
+ return null;
33
34
35
+ fast = pHead;
36
+ while(slow != fast) {
37
38
+ fast = fast.next;
39
40
41
+ return slow;
42
43
0 commit comments