728x90
189. Rotate Array
-
[LeetCode] 189. Rotate Array c++Coding Test/LeetCode 2022. 12. 23. 15:10
문제 Given an array, rotate the array to the right by k steps, where k is non-negative. Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4] 문제 해결 rotate는 맨 뒤 원소가 맨 앞원소로 이동된다. k 개수 만큼 nums맨뒤의 원소가 맨앞으로 rotate된다. 회전한 원소들이 기존 순서를 유지하여 rotate되는 것을 ..