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.
*/
const rotate = (nums, k) => {
if (nums.length < k) k %= nums.length;
const spliceArray = nums.splice(0, nums.length-k)
spliceArray.forEach(el => nums.push(el))
};
GitHub : https://github.com/developeSHG/Algorithm-LeetCode/tree/main/rotate-array
'Coding Test > LeetCode' 카테고리의 다른 글
[LeetCode] (Strings) Lv Easy. First Unique Character in a String (0) | 2023.02.06 |
---|---|
[LeetCode] (Array) Lv Easy. Contains Duplicate (0) | 2023.02.06 |
[LeetCode] (Design) Lv Easy. Shuffle an Array (0) | 2023.01.25 |
[LeetCode] (Math) Lv Easy. Fizz Buzz (0) | 2023.01.22 |
[LeetCode] (Dynamic Programming) Lv Easy. Climbing Stairs (0) | 2023.01.22 |
댓글