-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added README.md file for Rotate Array
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<h2><a href="https://leetcode.com/problems/rotate-array">Rotate Array</a></h2> <img src='https://img.shields.io/badge/Difficulty-Medium-orange' alt='Difficulty: Medium' /><hr><p>Given an integer array <code>nums</code>, rotate the array to the right by <code>k</code> steps, where <code>k</code> is non-negative.</p> | ||
|
||
<p> </p> | ||
<p><strong class="example">Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [1,2,3,4,5,6,7], k = 3 | ||
<strong>Output:</strong> [5,6,7,1,2,3,4] | ||
<strong>Explanation:</strong> | ||
rotate 1 steps to the right: [7,1,2,3,4,5,6] | ||
rotate 2 steps to the right: [6,7,1,2,3,4,5] | ||
rotate 3 steps to the right: [5,6,7,1,2,3,4] | ||
</pre> | ||
|
||
<p><strong class="example">Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [-1,-100,3,99], k = 2 | ||
<strong>Output:</strong> [3,99,-1,-100] | ||
<strong>Explanation:</strong> | ||
rotate 1 steps to the right: [99,-1,-100,3] | ||
rotate 2 steps to the right: [3,99,-1,-100] | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li> | ||
<li><code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code></li> | ||
<li><code>0 <= k <= 10<sup>5</sup></code></li> | ||
</ul> | ||
|
||
<p> </p> | ||
<p><strong>Follow up:</strong></p> | ||
|
||
<ul> | ||
<li>Try to come up with as many solutions as you can. There are at least <strong>three</strong> different ways to solve this problem.</li> | ||
<li>Could you do it in-place with <code>O(1)</code> extra space?</li> | ||
</ul> |