Skip to content

Commit aa783df

Browse files
authored
Merge pull request neetcode-gh#1419 from imevanc/Create-876-Middle-Of-The-Linked-List.js
Create: 876-Middle-Of-The-Linked-List.js
2 parents 152cbea + f6e9d17 commit aa783df

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy