|
| 1 | +<h2><a href="https://leetcode.com/problems/check-if-array-is-sorted-and-rotated">1878. Check if Array Is Sorted and Rotated</a></h2><h3>Easy</h3><hr><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> |
| 2 | + |
| 3 | +<p>There may be <strong>duplicates</strong> in the original array.</p> |
| 4 | + |
| 5 | +<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> |
| 6 | + |
| 7 | +<p> </p> |
| 8 | +<p><strong class="example">Example 1:</strong></p> |
| 9 | + |
| 10 | +<pre> |
| 11 | +<strong>Input:</strong> nums = [3,4,5,1,2] |
| 12 | +<strong>Output:</strong> true |
| 13 | +<strong>Explanation:</strong> [1,2,3,4,5] is the original sorted array. |
| 14 | +You can rotate the array by x = 3 positions to begin on the the element of value 3: [3,4,5,1,2]. |
| 15 | +</pre> |
| 16 | + |
| 17 | +<p><strong class="example">Example 2:</strong></p> |
| 18 | + |
| 19 | +<pre> |
| 20 | +<strong>Input:</strong> nums = [2,1,3,4] |
| 21 | +<strong>Output:</strong> false |
| 22 | +<strong>Explanation:</strong> There is no sorted array once rotated that can make nums. |
| 23 | +</pre> |
| 24 | + |
| 25 | +<p><strong class="example">Example 3:</strong></p> |
| 26 | + |
| 27 | +<pre> |
| 28 | +<strong>Input:</strong> nums = [1,2,3] |
| 29 | +<strong>Output:</strong> true |
| 30 | +<strong>Explanation:</strong> [1,2,3] is the original sorted array. |
| 31 | +You can rotate the array by x = 0 positions (i.e. no rotation) to make nums. |
| 32 | +</pre> |
| 33 | + |
| 34 | +<p> </p> |
| 35 | +<p><strong>Constraints:</strong></p> |
| 36 | + |
| 37 | +<ul> |
| 38 | + <li><code>1 <= nums.length <= 100</code></li> |
| 39 | + <li><code>1 <= nums[i] <= 100</code></li> |
| 40 | +</ul> |
0 commit comments