We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 50401df commit 30694a1Copy full SHA for 30694a1
876-middle-of-the-linked-list.js
@@ -0,0 +1,26 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * function ListNode(val) {
4
+ * this.val = val;
5
+ * this.next = null;
6
+ * }
7
+ */
8
9
+ * @param {ListNode} head
10
+ * @return {ListNode}
11
12
+const middleNode = function (head) {
13
+ if (head == null) return null
14
+ let count = 1
15
+ let iter = head
16
+ while (iter.next) {
17
+ iter = iter.next
18
+ count++
19
+ }
20
+ count = (count / 2) >> 0
21
+ while (count) {
22
+ head = head.next
23
+ count--
24
25
+ return head
26
+}
0 commit comments