.344.Reverse String
note:
list[::-1] :顺序相反操作
list[3::-1] :从第三个位置坐标开始 截取顺序相反
344. Reverse String
1) description
Write a function that reverses a string. The input string is given as an array of characters char[]
.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
You may assume all the characters consist of printable ascii characters.
Example 1
Input: ["h","e","l","l","o"]
Output: ["o","l","l","e","h"]
2)solution
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
for i in range(int((len(s)+1)/2)):
s[i], s[~i]= s[~i] , s[I]
s.reverse()
others's
return s[::-1]
网友评论