Skip to content

Commit 7fea737

Browse files
committed
Add solution #876
1 parent e7bfb8b commit 7fea737

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
844|[Backspace String Compare](./0844-backspace-string-compare.js)|Easy|
147147
846|[Hand of Straights](./0846-hand-of-straights.js)|Medium|
148148
867|[Transpose Matrix](./0867-transpose-matrix.js)|Easy|
149+
876|[Middle of the Linked List](./0876-middle-of-the-linked-list.js)|Easy|
149150
884|[Uncommon Words from Two Sentences](./0884-uncommon-words-from-two-sentences.js)|Easy|
150151
890|[Find and Replace Pattern](./0890-find-and-replace-pattern.js)|Medium|
151152
916|[Word Subsets](./0916-word-subsets.js)|Medium|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* 876. Middle of the Linked List
3+
* https://leetcode.com/problems/middle-of-the-linked-list/
4+
* Difficulty: Easy
5+
*
6+
* Given the head of a singly linked list, return the middle node of the linked list.
7+
*
8+
* If there are two middle nodes, return the second middle node.
9+
*/
10+
11+
/**
12+
* Definition for singly-linked list.
13+
* function ListNode(val, next) {
14+
* this.val = (val===undefined ? 0 : val)
15+
* this.next = (next===undefined ? null : next)
16+
* }
17+
*/
18+
/**
19+
* @param {ListNode} head
20+
* @return {ListNode}
21+
*/
22+
var middleNode = function(head) {
23+
let slow = head;
24+
let fast = head;
25+
26+
while (fast && fast.next) {
27+
slow = slow.next;
28+
fast = fast.next.next;
29+
}
30+
31+
return slow;
32+
};

0 commit comments

Comments
 (0)