Skip to content

Commit 202aaeb

Browse files
committed
Add solution #189
1 parent 7fd5db8 commit 202aaeb

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
167|[Two Sum II - Input Array Is Sorted](./0167-two-sum-ii-input-array-is-sorted.js)|Easy|
7878
169|[Majority Element](./0169-majority-element.js)|Easy|
7979
179|[Largest Number](./0179-largest-number.js)|Medium|
80+
189|[Rotate Array](./0189-rotate-array.js)|Medium|
8081
191|[Number of 1 Bits](./0191-number-of-1-bits.js)|Easy|
8182
203|[Remove Linked List Elements](./0203-remove-linked-list-elements.js)|Easy|
8283
206|[Reverse Linked List](./0206-reverse-linked-list.js)|Easy|

solutions/0189-rotate-array.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* 189. Rotate Array
3+
* https://leetcode.com/problems/rotate-array/
4+
* Difficulty: Medium
5+
*
6+
* Given an array, rotate the array to the right by k steps, where k is non-negative.
7+
*/
8+
9+
/**
10+
* @param {number[]} nums
11+
* @param {number} k
12+
* @return {void} Do not return anything, modify nums in-place instead.
13+
*/
14+
var rotate = function(nums, k) {
15+
nums.unshift(...nums.splice((k % nums.length) * -1));
16+
};

0 commit comments

Comments
 (0)