Skip to content

Commit fbf12aa

Browse files
Create 876. Middle of the Linked List.java
1 parent ed259ed commit fbf12aa

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//fast and slow pointer
2+
class Solution {
3+
public ListNode middleNode(ListNode head) {
4+
ListNode slow = head;
5+
ListNode fast = head;
6+
while (fast!=null && fast.next!=null) {
7+
fast = fast.next.next;
8+
slow = slow.next;
9+
}
10+
return slow;
11+
}
12+
}

0 commit comments

Comments
 (0)