Skip to content

Commit f6e9d17

Browse files
committed
Create: 876-Middle-Of-The-Linked-List.js
1 parent 43119ae commit f6e9d17

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* https://leetcode.com/problems/middle-of-the-linked-list/
3+
* Definition for singly-linked list.
4+
* function ListNode(val, next) {
5+
* this.val = (val===undefined ? 0 : val)
6+
* this.next = (next===undefined ? null : next)
7+
* }
8+
*/
9+
/**
10+
* @param {ListNode} head
11+
* @return {ListNode}
12+
*/
13+
var middleNode = function (head) {
14+
let first = head;
15+
let second = head;
16+
while (second != null && second.next != null) {
17+
first = first.next;
18+
second = second.next.next;
19+
}
20+
return first;
21+
};

0 commit comments

Comments
 (0)