编写一个函数,其作用是将输入的字符串反转过来。
示例 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 """ #return s[::-1] start = 0 end = len(s)-1 tmp=[i for i in s] while start < end: tmp[start],tmp[end] = tmp[end],tmp[start] start+=1 end-=1 return ‘‘.join(tmp)
原文地址:https://www.cnblogs.com/flashBoxer/p/9532431.html
时间: 2024-11-04 01:01:52