Find the middle element of an array. For even length, return the second middle element.
Example Input & Output
Example 1
Input
[1,2,3,4]
Output
3
Explanation
Second middle for even
Example 2
Input
[1,2,3,4,5]
Output
3
Explanation
Middle of 5 elements
Example 3
Input
[1,2,3]
Output
2
Explanation
Three elements
Example 4
Input
[1,2]
Output
2
Explanation
Two elements
Example 5
Input
[1]
Output
1
Explanation
Single
Algorithm Flow

Recommendation Algorithm Flow for Middle of List
Solution Approach
Best Answers
java
class Solution {
public int solution(int[] nums) {
return nums[nums.length/2];
}
}Related Linked List Challenges
Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
