[코테] 리트코드 문자열 조작 344.Reverse String 문제
344. Reverse String
문제 링크
https://leetcode.com/problems/reverse-string/description/
문제 설명
Write a function that reverses a string. The input string is given as an array of characters s.
You must do this by modifying the input array in-place with O(1) extra memory.
제한사항
- 1 <= s.length <= 105
- s[i] is a printable ascii character.
입출력 예 #1
- Input: s = [“h”,”e”,”l”,”l”,”o”]
- Output: [“o”,”l”,”l”,”e”,”h”]
입출력 예 #2
- Input: s = [“H”,”a”,”n”,”n”,”a”,”h”]
- Output: [“h”,”a”,”n”,”n”,”a”,”H”]
문제 풀이
리스트 뒤집기 함수로 풀이할 수 있다.
class Solution:
def reverseString(self, s: List[str]) -> None:
s.reverse()
Comments