java.lang.Object
g1701_1800.s1752_check_if_array_is_sorted_and_rotated.Solution

public class Solution extends Object
1752 - Check if Array Is Sorted and Rotated.<p>Easy</p> <p>Given an array <code>nums</code>, return <code>true</code> <em>if the array was originally sorted in non-decreasing order, then rotated <strong>some</strong> number of positions (including zero)</em>. Otherwise, return <code>false</code>.</p> <p>There may be <strong>duplicates</strong> in the original array.</p> <p><strong>Note:</strong> An array <code>A</code> rotated by <code>x</code> positions results in an array <code>B</code> of the same length such that <code>A[i] == B[(i+x) % A.length]</code>, where <code>%</code> is the modulo operation.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [3,4,5,1,2]</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> [1,2,3,4,5] is the original sorted array. You can rotate the array by x = 3 positions to begin on the the element of value 3: [3,4,5,1,2].</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [2,1,3,4]</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> There is no sorted array once rotated that can make nums.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [1,2,3]</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> [1,2,3] is the original sorted array. You can rotate the array by x = 0 positions (i.e. no rotation) to make nums.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 100</code></li> <li><code>1 <= nums[i] <= 100</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • check

      public boolean check(int[] nums)