Skip to content

Commit c94b18b

Browse files
authored
Update 189-rotate-array.js
1 parent b057fec commit c94b18b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

189-rotate-array.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,15 @@
44
* @return {void} Do not return anything, modify nums in-place instead.
55
*/
66
const rotate = function(nums, k) {
7-
nums.unshift(...nums.splice(nums.length - k));
7+
nums.unshift(...nums.splice(nums.length - k))
8+
};
9+
10+
// another
11+
12+
const rotate = function(nums, k) {
13+
let i = k
14+
while (i > 0) {
15+
nums.unshift(nums.pop())
16+
i--
17+
}
818
};

0 commit comments

Comments
 (0)