Skip to content

Commit ab64a31

Browse files
committed
Create README - LeetHub
1 parent 8e1f17f commit ab64a31

File tree

1 file changed

+40
-0
lines changed
  • 1878-check-if-array-is-sorted-and-rotated

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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>&nbsp;</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>&nbsp;</p>
35+
<p><strong>Constraints:</strong></p>
36+
37+
<ul>
38+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
39+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
40+
</ul>

0 commit comments

Comments
 (0)