프로그래밍/LeetCode
[LeetCode][Python3] 189. Rotate Array
snoopybox
2018. 11. 3. 23:29
Problem :
https://leetcode.com/problems/rotate-array/
My Solution :
class Solution:
def rotate(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: void Do not return anything, modify nums in-place instead.
"""
k %= len(nums)
nums[:] = nums[-k:] + nums[:-k]
Comment :
Note에서 요구하는 O(1) space 방법은 떠오르지 않아서 그냥 python 기본 문법인 slice를 활용하여 풀었다.