blob: be1853d240c74fc15cd9e4865b6717d669816134 (
plain)
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
|
# 344. Reverse String
"""
write a function that reverses a string. the input string is given as an
array of characters 's'. you must do this by modifying teh input array in
place with 'O(1)' extra memroy
"""
class Solution(object):
def reverseString(self, s):
"""
:type s: List[str]
:rtype: None Do not return anything, modify s in-place instead.
"""
s[:] = s[::-1]
if __name__ == "__main__":
obj = Solution()
s1 = "hello"
s2 = "Hannah"
obj.reverseString(s1)
obj.reverseString(s2)
print(s1)
print(s2)
|