Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.

Example 1:

Input: "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"

Note: In the string, each word is separated by single space and there will not be any extra space in the string.


 
 
Code
class Solution:
def reverseString3(self, s):
s = s.split(' ')
for i in range(len(s)):
s[i] = s[i][::-1]
return ' '.join(s)

[LeetCode] 557. Reverse Words in a String III_Easy tag: String的更多相关文章

  1. Leetcode#557. Reverse Words in a String III(反转字符串中的单词 III)

    题目描述 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" 输 ...

  2. leetcode 557. Reverse Words in a String III 、151. Reverse Words in a String

    557. Reverse Words in a String III 最简单的把空白之间的词反转 class Solution { public: string reverseWords(string ...

  3. [LeetCode] 557. Reverse Words in a String III 翻转字符串中的单词 III

    Given a string, you need to reverse the order of characters in each word within a sentence while sti ...

  4. Leetcode - 557. Reverse Words in a String III (C++) stringstream

    1. 题目:https://leetcode.com/problems/reverse-words-in-a-string-iii/discuss/ 反转字符串中的所有单词. 2. 思路: 这题主要是 ...

  5. LeetCode 557. Reverse Words in a String III (反转字符串中的单词 III)

    Given a string, you need to reverse the order of characters in each word within a sentence while sti ...

  6. LeetCode 557 Reverse Words in a String III 解题报告

    题目要求 Given a string, you need to reverse the order of characters in each word within a sentence whil ...

  7. leetCode 557. Reverse Words in a String I

    Input: "Let's take LeetCode contest" Output: "s'teL ekat edoCteeL tsetnoc" 解:输入一 ...

  8. [LeetCode] 443. String Compression_Easy tag:String

    Given an array of characters, compress it in-place. The length after compression must always be smal ...

  9. [LeetCode] 151. Reverse Words in a String 翻转字符串中的单词

    Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...

随机推荐

  1. JSON类库 Flexjson学习

    官方地址(需FQ):http://flexjson.sourceforge.net/ Flexjson 是一个将 Java 对象转成 JSON 的 类库,是一个深度转换的过程. 下面是我写的一个例子: ...

  2. linux学习路线图

  3. hihoCoder挑战赛28 题目2 : 二进制翻转

    题目2 : 二进制翻转 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 定义函数 Rev(x) 表示把 x 在二进制表示下翻转后的值 例如: Rev(4)=1,因为 4 ...

  4. Django的RestfulAPI框架RestFramework

    Django的Restful-API框架 安装框架 #sudo pip3 install django #sudo pip3 install markdown #sudo pip3 install d ...

  5. 【BZOJ1478】Sgu282 Isomorphism Pólya定理神题

    [BZOJ1478]Sgu282 Isomorphism 题意:用$m$种颜色去染一张$n$个点的完全图,如果一个图可以通过节点重新标号变成另外一个图,则称这两个图是相同的.问不同的染色方案数.答案对 ...

  6. iOS interface适配

  7. 微信小程序:wx.navigateTo中url无法跳转问题(app.json中配置的tabBar与wx.navigateTo中url引用相同页面导致)

    今天在做微信小程序时,设置wx.navigateTo页面跳转并传参数,点击始终没有效果,代码如下: //事件处理函数 newsDetail: function (event) { console.lo ...

  8. vim配置函数跳转(c/c++)

    暂时草记一下,有时间好好整理 ctags 如果只是查看函数与变量是在哪里定义的,用ctags就可以了. ctrl+]跳到定义的地方,ctrl+t跳回来. 想要像IDE那样在旁边显示函数与变量列表,用t ...

  9. wpgcms---单片页数据渲染

    单片页数据渲染,使用Twig的标签语法: <h1> {{ contentInfo.title }} </h1> {% autoescape false %} {{ conten ...

  10. vue--简单数据绑定

    <template> <div id="app"> {{msg}} //绑定数据 {{obj.name}} //绑定对象 <p v-for=" ...