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 0fdee39 commit 165d300Copy full SHA for 165d300
876.链表的中间结点.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
+var middleNode = function(head) {
13
+ let length = 0;
14
+ for (let t = head; t;) {
15
+ length++;
16
+ t = t.next;
17
+ }
18
+
19
+ length = length >> 1;
20
+ let result = head;
21
+ while (length > 0) {
22
+ result = result.next;
23
+ length--;
24
25
+ return result;
26
+};
0 commit comments