Skip to content

Commit f27c2f2

Browse files
committed
Create README - LeetHub
1 parent 84c21e4 commit f27c2f2

File tree

1 file changed

+38
-0
lines changed
  • 1752-check-if-array-is-sorted-and-rotated

1 file changed

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

0 commit comments

Comments
 (0)