Package g0101_0200.s0189_rotate_array
Class Solution
java.lang.Object
g0101_0200.s0189_rotate_array.Solution
189 - Rotate Array.<p>Medium</p>
<p>Given an array, rotate the array to the right by <code>k</code> steps, where <code>k</code> is non-negative.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,2,3,4,5,6,7], k = 3</p>
<p><strong>Output:</strong> [5,6,7,1,2,3,4]</p>
<p><strong>Explanation:</strong></p>
<pre><code> 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]
</code></pre>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [-1,-100,3,99], k = 2</p>
<p><strong>Output:</strong> [3,99,-1,-100]</p>
<p><strong>Explanation:</strong></p>
<pre><code> rotate 1 steps to the right: [99,-1,-100,3]
rotate 2 steps to the right: [3,99,-1,-100]
</code></pre>
<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><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>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
rotate
public void rotate(int[] nums, int k)
-