관리 메뉴

솜씨좋은장씨

[leetCode] 344. Reverse String (Python) 본문

Programming/코딩 1일 1문제

[leetCode] 344. Reverse String (Python)

솜씨좋은장씨 2020. 8. 13. 23:24
728x90
반응형

Write a function that reverses a string. The input string is given as an array of characters char[].

Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

You may assume all the characters consist of printable ascii characters.

 

Example 1:

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

Example 2:

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

Solution

class Solution:
    def reverseString(self, s):
        s.reverse()

 

 

SOMJANG/CODINGTEST_PRACTICE

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

 

Comments