https://leetcode.com/explore/interview/card/top-interview-questions-easy/92/array/646/
배열 회전하기 문제이다.
/**
* @param {number[]} nums
* @param {number} k
* @return {void} Do not return anything, modify nums in-place instead.
*/
var rotate = function(nums, k) {
k = k % nums.length;
const temp = nums.splice(nums.length-k , nums.length - 1)
nums.unshift(...temp);
return nums;
};
'개발 > 알고리즘' 카테고리의 다른 글
[프로그래머스] 수식 최대화 (0) | 2021.07.17 |
---|---|
[프로그래머스] 괄호변환 (2) | 2021.07.08 |
[LeetCode] Best Time to Buy and Sell Stock II (1) | 2021.07.01 |
[LeetCode] 111. Minimum Depth of Binary Tree (트리 깊이 구하기) (0) | 2021.03.15 |
[LeetCode] 101. Symmetric Tree (0) | 2021.01.27 |