본문 바로가기
Coding Test/LeetCode

[LeetCode] (Array) Lv Easy. Rotate Array

by song.ift 2023. 1. 31.

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

 

javascript
닫기
/** * @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

 

GitHub - developeSHG/Algorithm-LeetCode: 릿코드 소스코드

릿코드 소스코드. Contribute to developeSHG/Algorithm-LeetCode development by creating an account on GitHub.

github.com

 

댓글