美文网首页
[python] 2019-03-02

[python] 2019-03-02

作者: 原来是酱紫呀 | 来源:发表于2019-03-02 22:56 被阅读0次

.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]

相关文章

网友评论

      本文标题:[python] 2019-03-02

      本文链接:https://www.haomeiwen.com/subject/pwquuqtx.html