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
- 그래프(Graph)
- 이분 그래프(Bipartite Graph)
- 분할 정복(Divide and Conquer)
- DFS & BFS
- 알고리즘 개념
- 백준 9012번
- BFS(Breadth First Search)
- 백준 21606번
- DFS
- 이분 탐색(Binary Search)
- 그리디 알고리즘(Greedy Algorithm)
- 백준 1948번
- 백준 1707번
- 백준 2261번
- 백준 18352번
- 다익스트라 알고리즘(Dijkstra Algorithm)
- 동적 프로그래밍(Dynamic Programming)
- 백준 2504번
- 백준 2812번
- 트리(Tree)
- 위상 정렬(Topology Sort)
- 백준 10000번
- 큐(Queue)
- 플로이드 워셜 알고리즘(Floyd-Warshall Algorithm)
- DFS(Depth First Search)
- 위상 정렬(Topological Sort)
- 백준 17608번
- 스택(Stack)
- 백준 2493번
- BFS
Archives
- Today
- Total
Always Be Wise
문자열 조작 : 문자열 뒤집기(리트코드 344번) 본문
728x90
▶ 문제 : https://leetcode.com/problems/reverse-string/
Reverse String - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
##### 문제 #####
문자열을 뒤집는 함수를 작성하라. 입력값은 문자 배열이며, 리턴 없이 리스트 내부를 직접 조작하라.
##### 입력 #####
["h", "e", "l", "l", "o"]
##### 출력 #####
["o", "l", "l", "e", "h"]
▶ 접근 방법
투 포인터를 이용하여 자리를 바꾸는 방법, 파이썬 내장 함수를 이용하는 방법을 사용하였다.
▶ 풀이 코드
from typing import List
ex_list = ["h", "e", "l", "l", "o"]
def reverse_string(list: List[str]) -> None:
left, right = 0, len(list) -1
while left < right:
list[left], list[right] = list[right], list[left]
left += 1
right -= 1
reverse_string(ex_list)
print(ex_list)
ex_list.reverse()
print(ex_list)
▶ 관련 링크
'알고리즘 > 리트코드' 카테고리의 다른 글
문자열 조작 : 가장 긴 팰린드롬 부분 문자열(리트코드 5번) (0) | 2021.12.14 |
---|---|
문자열 조작 : 그룹 애너그램(리트코드 49번) (0) | 2021.12.14 |
문자열 조작 : 가장 흔한 단어(리트코드 819번) (0) | 2021.12.14 |
문자열 조작 : 로그 파일 재정렬(리트코드 937번) (0) | 2021.12.14 |
문자열 조작 : 유효한 팰린드롬(리트코드 125번) (0) | 2021.12.14 |