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

Class Solution

leetcode/344. Reverse String.py:8–20  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6'''
7
8class Solution(object):
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 1

Calls

no outgoing calls

Tested by

no test coverage detected