【Question】

  • Write a function that takes a string as input and returns the string reversed.

  • Example:

Given s = "hello", return "olleh".


【My Solution】

  • Slice 切片
class Solution(object):
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
s = s[::-1]
return s
  • 分析

    利用python的切片特性,反向切片即可

【LeetCode】#344 Reverse String的更多相关文章

  1. 【leetcode】344. Reverse String

    problem 344. Reverse String solution: class Solution { public: void reverseString(vector<char> ...

  2. 【LeetCode】344. Reverse String 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 新构建字符串 原地翻转 日期 题目地址:https://lee ...

  3. 【一天一道LeetCode】#344. Reverse String

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...

  4. 【LeetCode】541. Reverse String II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...

  5. 【leetcode】557. Reverse Words in a String III

    Algorithm [leetcode]557. Reverse Words in a String III https://leetcode.com/problems/reverse-words-i ...

  6. 【LeetCode】481. Magical String 解题报告(Python)

    [LeetCode]481. Magical String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:/ ...

  7. 【LeetCode】880. Decoded String at Index 解题报告(Python)

    [LeetCode]880. Decoded String at Index 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

  8. 【LeetCode】151. Reverse Words in a String

    Difficulty: Medium  More:[目录]LeetCode Java实现 Description Given an input string, reverse the string w ...

  9. 【LeetCode】557. Reverse Words in a String III 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...

随机推荐

  1. IE6不支持min-heightt和min-width的解决办法

    IE6不支持min-height的解决办法 最小高度min-height是很有用的,但IE6却不支持.真烦人.有没有办法呢? 我们可以利用IE6不识别!important来实现: height:aut ...

  2. php如何去掉二维数组中重复的元素?

    $arr=array("=>array("a","b")); 我想得到的结果是:只输出第一项(第一项和第三项相同,去第一项)和第二项这个怎么解决 ...

  3. 浅析Java.lang.ProcessBuilder类

    最近由于工作需要把用户配置的Hive命令在Linux环境下执行,专门做了一个用户管理界面特地研究了这个不经常用得ProcessBuilder类.所以把自己的学习的资料总结一下. 一.概述      P ...

  4. Java 异常处理 练习2

    建立exception包,建立Bank类,类中有变量double  balance表示存款,Bank类的构造方法能增加存款,Bank类中有取款的发方法withDrawal(double dAmount ...

  5. Mark Down 尝试

    Hello World iawriter sublime text

  6. Git使用指南(1)——Git配置命令

    配置用户信息 git config --global user.name bongxin git config --global user.email bongxin@yeah.net 配置文本编辑器 ...

  7. Android 软件盘 Editext 问题

    显示的问题:android:windowSoftInputMode="adjustPan|stateHidden" 弹出布局Editext并且挤上去 android:windowS ...

  8. Linux and the Device Tree

    来之\kernel\Documentation\devicetree\usage-model.txt Linux and the Device Tree ----------------------- ...

  9. 遗传算法在JobShop中的应用研究(part 7:整体流程)

    """ pop是种群,种群中的每个个体的形式是,(makespan, 染色体)""" pop = [(ComputeStartTimes(g ...

  10. h5移动端让文字不可选中复制

    可以用css属性来控制 -moz-user-select:none; -webkit-user-select:none;