## Algorithm

Problem Name: 876. Middle of the Linked List

If there are two middle nodes, return the second middle node.

Example 1:

Output: [3,4,5]
Explanation: The middle node of the list is node 3.

Example 2:

Output: [4,5,6]
Explanation: Since the list has two middle nodes with values 3 and 4, we return the second one.

Constraints:

• The number of nodes in the list is in the range [1, 100].
• 1 <= Node.val <= 100

## Code Examples

### #1 Code Example with C++ Programming

Code - C++ Programming

class Solution {
public:
while(b && b->next) a = a->next, b = b->next->next;
return a;
}
};
Copy The Code &

Input

cmd

Output

cmd
[3,4,5]

### #2 Code Example with Java Programming

Code - Java Programming

class Solution {
while (fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
}
return slow;
}
}
Copy The Code &

Input

cmd

Output

cmd
[3,4,5]

### #3 Code Example with Javascript Programming

Code - Javascript Programming

const middleNode = function (head) {
if (head == null) return null
let count = 1
while (iter.next) {
iter = iter.next
count++
}
count = (count / 2) >> 0
while (count) {
count--
}
}
Copy The Code &

Input

cmd

Output

cmd
[4,5,6]

### #4 Code Example with Python Programming

Code - Python Programming

class Solution:
n += 1
for _ in range(n // 2):
root = root.next
return root
Copy The Code &

Input

cmd

Output

cmd
[4,5,6]

### #5 Code Example with C# Programming

Code - C# Programming

namespace LeetCode
{
{
{

while (fast != null && fast.next != null)
{
fast = fast.next.next;
slow = slow.next;
}

return slow;
}
}
}
Copy The Code &

Input

cmd