Reverse the order of elements in a deque (array). The front becomes the back and vice versa.
Example Input & Output
Example 1
Input
[10,20,30]
Output
[30,20,10]
Explanation
Three elements
Example 2
Input
[1,2]
Output
[2,1]
Explanation
Two elements
Example 3
Input
[1,2,3,4,5]
Output
[5,4,3,2,1]
Explanation
Reverse order
Example 4
Input
[1]
Output
[1]
Explanation
Single
Example 5
Input
[]
Output
[]
Explanation
Empty
Algorithm Flow

Recommendation Algorithm Flow for Deque Reverse
Solution Approach
Best Answers
java
class Solution {
public int[] solution(int[] nums) {
int n=nums.length;int[] r=new int[n];
for(int i=0;i<n;i++)r[i]=nums[n-1-i];
return r;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
