Thief of Wealth
Published 2021. 7. 10. 11:35
[LeetCode] Rotate Array 개발/알고리즘

https://leetcode.com/explore/interview/card/top-interview-questions-easy/92/array/646/

 

Explore - LeetCode

LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore.

leetcode.com

 

배열 회전하기 문제이다.

 

/**
 * @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;
};
profile on loading

Loading...