题目要求

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.

题目分析及思路

题目给出一个字符串,要求将每个词中的字母顺序颠倒,但仍旧保留空格和原先的词序。可以用.split()方法将词分开并遍历,最后倒序并组成新的字符串。

python代码

class Solution:

def reverseWords(self, s: 'str') -> 'str':

s = s.split()

res = ''

for i in s:

res += i[::-1]

res += ' '

return res.strip()

LeetCode 557 Reverse Words in a String III 解题报告的更多相关文章

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

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

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

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

  3. 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 ...

  4. [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 ...

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

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

  6. 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 ...

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

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

  8. 557. Reverse Words in a String III【easy】

    557. Reverse Words in a String III[easy] Given a string, you need to reverse the order of characters ...

  9. Week4 - 500.Keyboard Row & 557.Reverse Words in a String III

    500.Keyboard Row & 557.Reverse Words in a String III 500.Keyboard Row Given a List of words, ret ...

随机推荐

  1. swift 遍历枚举

      // see at http://swifter.tips/enum-enumerate/ // 貌似有些空格在粘贴的时候没有了...    = =! import Foundation   en ...

  2. MSSQL 2012 修改所有表的架构Schame

    ALTER SCHEMA [dbo] TRANSFER [sq_szswdjd].COM_Category ); declare csr1 cursor for select 'Name' = nam ...

  3. Install elasticsearch-head: – for Elasticsearch 5.x

    Running as a plugin of Elasticsearch Install elasticsearch-head:– for Elasticsearch 5.x:site plugins ...

  4. WPF Input Validation Using MVVM

    Data validation is a key part in WPF.Validation is used to alert the user that the data he entered i ...

  5. python进行数据分析

    1.  python进行数据分析----线性回归 2. python进行数据分析------相关分析 3. python进行数据分析---python3卡方 4. 多重响应分析,多选题二分法思路 5. ...

  6. Linux监控平台介绍 zabbix监控介绍 安装zabbix 忘记Admin密码如何做

  7. fiddler工作原理和代理设置

    1,什么是Fiddler Fiddler是一个http协议调试代理工具,它能够记录客户端和服务器之间的所有 HTTP请求,可以针对特定的HTTP请求,分析请求数据.设置断点.调试web应用.修改请求的 ...

  8. Rsync实现多台Windows工作电脑文件同步

    你要准备的软件有: 最新版 Rsync for windows 服务端:cwRsync_Server_2.1.5_Installer.zip 客户端:cwRsync_2.1.5_Installer.z ...

  9. 【!Important】Zookeeper用来做什么的,有几种类型的节点

    zookeeper=文件系统+通知机制 一.Zookeeper提供了什么 1.文件系统 Zookeeper维护一个类似文件系统的数据结构 每个子目录项如NameService都被称为znoed,和文件 ...

  10. Redmine发布新闻,自动发送邮件功能失效恢复

    问题描述:操作数据库,修改项目公开状体后,创建新闻,自动发送邮件功能失效. 问题检查和恢复测试: 1.检查管理员权限 2.重新手动配置项目公开状态,覆盖数据操作 3.对比其他正常项目数据库状态,进行恢 ...