diff options
Diffstat (limited to 'reverse_string.py')
-rw-r--r-- | reverse_string.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/reverse_string.py b/reverse_string.py new file mode 100644 index 0000000..be1853d --- /dev/null +++ b/reverse_string.py @@ -0,0 +1,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) |