We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c13f1a7 commit 6f7db29Copy full SHA for 6f7db29
1 file changed
SDE_Sheet/MiddleOfTheLinkedList.js
@@ -0,0 +1,22 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * public class ListNode {
4
+ * int val;
5
+ * ListNode next;
6
+ * ListNode() {}
7
+ * ListNode(int val) { this.val = val; }
8
+ * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
9
+ * }
10
+ */
11
+class Solution {
12
+ public ListNode middleNode(ListNode head) {
13
+ ListNode slow = head;
14
+ ListNode fast = head;
15
+
16
+ while(fast != null && fast.next != null){
17
+ fast = fast.next.next;
18
+ slow = slow.next;
19
+ }
20
+ return slow;
21
22
+}
0 commit comments