Given an array representing a queue, return the front element (first element) without removing it. Return 0 if empty.
Example Input & Output
Example 1
Input
[10,20]
Output
10
Example 2
Input
[]
Output
0
Example 3
Input
[5]
Output
5
Example 4
Input
[7,8,9]
Output
7
Example 5
Input
[1,2,3]
Output
1
Algorithm Flow

Recommendation Algorithm Flow for Queue Peek Front
Solution Approach
Best Answers
java
class Solution {
public int solution(int[] nums) {
return nums.length>0?nums[0]:0;
}
}Related Queue Challenges
Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
