24. Middle of the List
Easy
You are given the head of a linked list and must return the value of the middle node. If the list has an even number of nodes, choose the second of the two middle nodes. For an empty list, return null.
Example 1
Input: head = [4, 8, 15, 16, 23]
Output: 15
Example 2
Input: head = [3, 7, 11, 19]
Output: 11
Constraints
- 0 <= tamanho da lista <= 10000
- -100000 <= val <= 100000.
Linked listTwo pointers
Saved in this browser
Caso 1
head =
[4,8,15,16,23]
Expected =
15
Caso 2
head =
[3,7,11,19]
Expected =
11
Run checks these 2 cases. Submit runs all 6, including hidden ones.