Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 109dcae

Browse files
committed
876
1 parent 5b29d1d commit 109dcae

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

876. Middle of The Linked List.js

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

0 commit comments

Comments
 (0)