344. 反转字符串python
编写一个函数,其作用是将输入的字符串反转过来。
示例 1:
输入: "hello" 输出: "olleh"
示例 2:
输入: "A man, a plan, a canal: Panama" 输出: "amanaP :lanac a ,nalp a ,nam A"
方法一
class Solution: def reverseString(self, s): """ :type s: str :rtype: str """ s = s[::-1] return s
方法二
class Solution: def reverseString(self, s): """ :type s: str :rtype: str """ s1 = '' for i in range(len(s)-1,-1,-1): s1 += s[i] return s1