请编写一个函数,其功能是将输入的字符串反转过来。

示例:

输入:s = "hello"
返回:"olleh"

思路

Python里面的切片用来解决这个问题就很快了,仅仅一行就实现了反转字符串!

赞美Python!

class Solution:
    def reverseString(self, s):
        """
        :type s: str
        :rtype: str
        """
        return s[::-1]

相关文章:

  • 2021-08-14
  • 2021-06-13
  • 2021-06-14
  • 2021-09-23
  • 2021-11-12
  • 2021-12-31
猜你喜欢
  • 2021-11-20
  • 2022-01-22
  • 2021-07-31
  • 2021-10-06
  • 2022-12-23
  • 2021-09-22
  • 2021-08-22
相关资源
相似解决方案