Skip to content

Commit a1176f3

Browse files
Create README - LeetHub
1 parent 4ad83cc commit a1176f3

File tree

1 file changed

+34
-0
lines changed
  • shortest-unsorted-continuous-subarray

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<h2>581. Shortest Unsorted Continuous Subarray</h2><h3>Medium</h3><hr><div><p>Given an integer array <code>nums</code>, you need to find one <b>continuous subarray</b> that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order.</p>
2+
3+
<p>Return <em>the shortest such subarray and output its length</em>.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong>Example 1:</strong></p>
7+
8+
<pre><strong>Input:</strong> nums = [2,6,4,8,10,9,15]
9+
<strong>Output:</strong> 5
10+
<strong>Explanation:</strong> You need to sort [6, 4, 8, 10, 9] in ascending order to make the whole array sorted in ascending order.
11+
</pre>
12+
13+
<p><strong>Example 2:</strong></p>
14+
15+
<pre><strong>Input:</strong> nums = [1,2,3,4]
16+
<strong>Output:</strong> 0
17+
</pre>
18+
19+
<p><strong>Example 3:</strong></p>
20+
21+
<pre><strong>Input:</strong> nums = [1]
22+
<strong>Output:</strong> 0
23+
</pre>
24+
25+
<p>&nbsp;</p>
26+
<p><strong>Constraints:</strong></p>
27+
28+
<ul>
29+
<li><code>1 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
30+
<li><code>-10<sup>5</sup> &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
31+
</ul>
32+
33+
<p>&nbsp;</p>
34+
<strong>Follow up:</strong> Can you solve it in <code>O(n)</code> time complexity?</div>

0 commit comments

Comments
 (0)