(牛客网)字符串-原串翻转(Python)

链接:https://www.nowcoder.com/questionTerminal/2442435405fa432b99b8ec1cb0315902?orderByHotValue=1&questionTypes=000100&mutiTagIds=579&page=2&onlyReference=false
来源:牛客网
请实现一个算法,在不使用额外数据结构和储存空间的情况下,翻转一个给定的字符串(可以使用单个过程变量)。

给定一个string iniString,请返回一个string,为翻转后的字符串。保证字符串的长度小于等于5000。

测试样例:

"This is nowcoder"
返回:"redocwon si sihT"
# -*- coding:utf-8 -*-
class Reverse:
    def reverseString(self, iniString):
        # write code here
        string = ''.join(reversed(iniString))  #如果不加join则返回的就是列表
        return string

猜你喜欢

转载自blog.csdn.net/qq_42633819/article/details/88632882