344. Reverse String Python3

Yelim Kim·2021년 9월 12일
0
post-thumbnail

Problem

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

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:

1 <= s.length <= 105
s[i] is a printable ascii character.

My code

class Solution:
    def reverseString(self, s: List[str]) -> None:
        s.reverse()

Review

Runtime(184ms), Memory(18.8MB)

[::-1]을 사용하고 싶으면 s[:] = s[::-1]
제가 저 코드로 똑같이 세 번 정도 돌려봤는데 런타임이 215ms였다가 184ms였다가 263ms이었다가...

거꾸로 출력
.reverse()

profile
뜬금없지만 세계여행이 꿈입니다.

0개의 댓글