File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 146
146
844|[ Backspace String Compare] ( ./0844-backspace-string-compare.js ) |Easy|
147
147
846|[ Hand of Straights] ( ./0846-hand-of-straights.js ) |Medium|
148
148
867|[ Transpose Matrix] ( ./0867-transpose-matrix.js ) |Easy|
149
+ 876|[ Middle of the Linked List] ( ./0876-middle-of-the-linked-list.js ) |Easy|
149
150
884|[ Uncommon Words from Two Sentences] ( ./0884-uncommon-words-from-two-sentences.js ) |Easy|
150
151
890|[ Find and Replace Pattern] ( ./0890-find-and-replace-pattern.js ) |Medium|
151
152
916|[ Word Subsets] ( ./0916-word-subsets.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments