티스토리 뷰
반응형
제약 : 리턴 없이 리스트 내부를 직접 조작
Using two pointers
def reverse_string(arr:list) -> None:
left, right = 0, len(arr) - 1
while left<right:
arr[left], arr[right] = arr[right], arr[left]
left+=1
right -=1
left, right 인덱스를 정해서 뒤집는 방식
Pythonic way
def reverse_string2(arr: list) -> None:
# arr.reverse()
arr[:] = arr[::-1]
Time complexity가 크게 차이가 안나기 때문에,
조금이라도 짧은 pythonic way 를 추천
반응형
'Development > Algorithms' 카테고리의 다른 글
[알고리즘]First non-repeating character (0) | 2021.06.27 |
---|---|
Valid Palindrome in python3 (0) | 2020.07.29 |
Leetocode 378 Kth Smallest Element in a Sorted Matrix (0) | 2020.06.22 |
Leetcode No. 234 && 206 Linked List basic Problem (1) | 2020.06.09 |
Leetcode 35 Search insert Position (0) | 2020.06.08 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 한빛미디어
- error
- 키보드
- Git
- leetcode
- Algorithm
- palindrome
- Fine-Tuning
- K8S
- Python
- 파이썬
- Shell
- feed-forward
- Kubernetes
- book
- LLM
- Container
- collator
- BASIC
- kubernetes context
- AWS
- go
- 나는리뷰어다
- Gemma
- docker
- csv
- Binary
- lllm
- 책리뷰
- kubens
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함
반응형