MCPcopy Create free account
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / reverseString2

Method reverseString2

leetcode/344. Reverse String.py:11–20  ·  view source on GitHub ↗
(self, s)

Source from the content-addressed store, hash-verified

9 def reverseString(self, s):
10 return s[::-1]
11 def reverseString2(self, s):
12 if not s or len(s) < 2:
13 return s
14 slist = list(s)
15 start, end = 0, len(s)-1
16 while start < end:
17 slist[start], slist[end] = slist[end], slist[start]
18 start += 1
19 end -= 1
20 return "".join(slist)
21
22s = Solution()
23print(s.reverseString("hello"))

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected