[LeetCode][Python3] 189. Rotate Array
2018. 11. 3. 23:29 |
프로그래밍/LeetCode
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를 활용하여 풀었다.
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 204. Count Primes (0) | 2018.11.04 |
---|---|
[LeetCode][Python3] 202. Happy Number (0) | 2018.11.04 |
[LeetCode][Python3] 191. Number of 1 Bits (0) | 2018.11.04 |
[LeetCode][Python3] 190. Reverse Bits (0) | 2018.11.04 |
[LeetCode][Python3] 172. Factorial Trailing Zeroes (0) | 2018.11.03 |
[LeetCode][Python3] 171. Excel Sheet Column Number (0) | 2018.11.03 |
[LeetCode][Python3] 122. Best Time to Buy and Sell Stock II (0) | 2018.11.03 |
[LeetCode][Python3] 88. Merge Sorted Array (0) | 2018.11.03 |
최근에 달린 댓글 최근에 달린 댓글