File tree 2 files changed +17
-0
lines changed
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 77
77
167|[ Two Sum II - Input Array Is Sorted] ( ./0167-two-sum-ii-input-array-is-sorted.js ) |Easy|
78
78
169|[ Majority Element] ( ./0169-majority-element.js ) |Easy|
79
79
179|[ Largest Number] ( ./0179-largest-number.js ) |Medium|
80
+ 189|[ Rotate Array] ( ./0189-rotate-array.js ) |Medium|
80
81
191|[ Number of 1 Bits] ( ./0191-number-of-1-bits.js ) |Easy|
81
82
203|[ Remove Linked List Elements] ( ./0203-remove-linked-list-elements.js ) |Easy|
82
83
206|[ Reverse Linked List] ( ./0206-reverse-linked-list.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments