물음표 살인마의 개발블로그

알고리즘 문제/Leetcode

344. Reverse String

BEstyle 2022. 12. 22. 17:02

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.

 

Example 1:

Input: s = ["h","e","l","l","o"]
Output: ["o","l","l","e","h"]

Example 2:

Input: s = ["H","a","n","n","a","h"]
Output: ["h","a","n","n","a","H"]

 

Constraints:


class Solution:
    def reverseString(self, s: List[str]) -> None:
        """
        Do not return anything, modify s in-place instead.
        """
        leng=len(s)
        for i in range(int(len(s)/2)):
            s[i],s[-1-i]=s[-1-i],s[i]

'알고리즘 문제 > Leetcode' 카테고리의 다른 글

977. Squares of a Sorted Array  (0) 2022.12.22
1768. Merge Strings Alternately  (0) 2022.12.22
2108. Find First Palindromic String in the Array  (0) 2022.12.20
832. Flipping an Image  (0) 2022.12.20
557. Reverse Words in a String III  (0) 2022.12.20