Description
Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero).
Examples
Input:
nums = [3,4,5,1,2]Output:
trueExplanation:
[1,2,3,4,5] rotated 3 positions.
Input:
nums = [3, 4, 5, 1, 2]Output:
trueExplanation:
[1,2,3,4,5] rotated 3 positions gives [3,4,5,1,2].
Input:
nums = [2,1,3,4]Output:
falseExplanation:
No rotation of a sorted array can produce [2,1,3,4]. A sorted version would be [1,2,3,4], but rotating it any number of positions cannot create the given array where 1 comes after 2 but before 3.
Constraints
- •
1 ≤ nums.length ≤ 100 - •
1 ≤ nums[i] ≤ 100