We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b3398ef commit ef2b5c7Copy full SHA for ef2b5c7
Python/reverse-string.py
@@ -0,0 +1,33 @@
1
+# Time: O(n)
2
+# Space: O(n)
3
+
4
+# Write a function that takes a string as input and
5
+# returns the string reversed.
6
+#
7
+# Example:
8
+# Given s = "hello", return "olleh".
9
10
+class Solution(object):
11
+ def reverseString(self, s):
12
+ """
13
+ :type s: str
14
+ :rtype: str
15
16
+ string = list(s)
17
+ i, j = 0, len(string) - 1
18
+ while i < j:
19
+ string[i], string[j] = string[j], string[i]
20
+ i += 1
21
+ j -= 1
22
+ return "".join(string)
23
24
25
26
27
+class Solution2(object):
28
29
30
31
32
33
+ return s[::-1]
0 commit comments