[LeetCode] 557. Reverse Words in a String III_Easy tag: String
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.
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的更多相关文章
- Leetcode#557. Reverse Words in a String III(反转字符串中的单词 III)
题目描述 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" 输 ...
- 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 ...
- [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 ...
- Leetcode - 557. Reverse Words in a String III (C++) stringstream
1. 题目:https://leetcode.com/problems/reverse-words-in-a-string-iii/discuss/ 反转字符串中的所有单词. 2. 思路: 这题主要是 ...
- 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 ...
- 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 ...
- leetCode 557. Reverse Words in a String I
Input: "Let's take LeetCode contest" Output: "s'teL ekat edoCteeL tsetnoc" 解:输入一 ...
- [LeetCode] 443. String Compression_Easy tag:String
Given an array of characters, compress it in-place. The length after compression must always be smal ...
- [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& ...
随机推荐
- Elasticsearch学习之深入搜索三 --- best fields策略
1. 为帖子数据增加content字段 POST /forum/article/_bulk { "} } { "doc" : {"content" : ...
- vue项目打包之后页面空白解决办法
之前项目遇到个情况,npm run build打包之后上传到服务器后,index.html打开一片空白,资源都加载了,但是就是不显示. 然后百度找了原因,修改了两处地方 一.修改 assetsPubl ...
- 题目1010:A + B(字符串转数字)
题目链接:http://ac.jobdu.com/problem.php?pid=1010 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- Nginx写IO占用高故障处理
文章来源:<https://www.centos.bz/2015/04/handle-nginx-write-io-problem/> 故障现象 突然收到一台服务器负载过高告警,紧接着网站 ...
- CF 434C Tachibana Kanade's Tofu[数位dp+AC自动机]
Solution //本代码压掉后两维 #include<cstdio> #define max(a,b) (a<b?b:a) using namespace std; inline ...
- Django配合MySQL学习Django模型外键的建立和使用
Django 模型建立外键 在模型中建立外键是很简单的,基本操作如下 class Table(models.Model) column_name = models.ForeignKey(other-T ...
- Unity3D笔记 切水果三 切水果
一.创建一个Apple00,拖拽Prfabs下的Sprite命名为Apple00,添加碰撞器Box Collider,编写代码Knife Rey1.js 二.做被切的苹果 步骤和一是一样的,但是被切的 ...
- gzip: stdin:unexpected end of file
原因是文件下载的不完整,重新下载就好了,
- POJ--1050--To the Max(线性动规,最大子矩阵和)
To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44723 Accepted: 23679 Descript ...
- 基于Solr和Zookeeper的分布式搜索方案的配置
1.1 什么是SolrCloud SolrCloud(solr 云)是Solr提供的分布式搜索方案,当你需要大规模,容错,分布式索引和检索能力时使用 SolrCloud.当一个系统的索引数据量少的时候 ...