题解 | #反转字符串#

反转字符串

http://www.nowcoder.com/practice/c3a6afee325e472386a1c4eb1ef987f3

#
# 反转字符串
# @param str string字符串 
# @return string字符串
#
def swap(str1,i,j):
    t = str1[i]
    str1[i] = str1[j]
    str1[j] = t
class Solution:
    def solve(self , str1):
        # write code here
        if str1 is None or str1 == "": return str1
        str2 = list(str1)
        i,j = 0,len(str2)-1
        while i<j:
            swap(str2, i, j)
            i+=1;j-=1
        return ''.join(str2)
全部评论

相关推荐

牛奶配面包:第二个经典博弈题目吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务