Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- k8s
- easy
- Dynamic Programming
- Observer Pattern
- github
- Kotlin
- java
- 피보나치
- BubbleSort
- Programmers
- Backjoon
- 파이썬
- 백준
- golang
- Top-down
- kubernetes
- 알고리즘
- Singleton Pattern
- docker
- KAKAO
- GKE
- cpu scheduling
- Python
- 그리디
- Codility
- mobaXTerm
- GCP
- go
- LeetCode
Archives
- Today
- Total
To Be Developer
[LeetCode] 189. Rotate Array.py 본문
class Solution(object):
def rotate(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: None Do not return anything, modify nums in-place instead.
"""
# 문제 설명
'''
nums 배열이 input으로 주어지는데
뒤에서 부터 k 개를 꺼내 앞으로 붙여라
ex) nums = [1,2,3,4,5,6,7]
k = 3
step 1 : [7,1,2,3,4,5,6]
step 2 : [6,7,1,2,3,4,5]
step 3 : [5,6,7,1,2,3,4]
'''
# nums 의 길이를 구한다
ln = len(nums)
# k 번 반복하여 nums의 맨 마지막 원소를 꺼내
# 0번 인덱스에 삽입한다.
for i in range(k):
nums.insert(0, nums.pop(ln-1))
if __name__ == "__main__":
nums = [1,2,3,4,5,6,7]
k = 3
print(Solution().rotate(nums, k))
'알고리즘 > LeetCode' 카테고리의 다른 글
[LeetCode] 231. Power of Two (0) | 2019.03.13 |
---|---|
[LeetCode] 225. Implement Stack using Queues (0) | 2019.03.13 |
[LeetCode] 7. Reverse Integer (0) | 2019.03.06 |
[LeetCode] Two Sum ll - Input array is sorted (0) | 2019.03.05 |
[LeetCode] 566. Reshape the Matrix (0) | 2019.03.04 |