python--leetcode557. Reverse Words in a String III
来源:互联网 发布:js判断哪个tr被双击 编辑:程序博客网 时间:2024/05/28 05:13
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(object): def reverseWords(self, s): """ :type s: str :rtype: str """ a=s.split() res=[] for i in range(len(a)): res.append(a[i][::-1]) res=' '.join(res) return ress=Solution()s.reverseWords("ok saf dww")更简短的代码:
def reverseWords(self, s): return ' '.join(x[::-1] for x in s.split())
阅读全文
1 0
- leetcode557. Reverse Words in a String III
- leetcode557. Reverse Words in a String III
- LeetCode557 Reverse Words in a String III
- Leetcode557. Reverse Words in a String III
- python--leetcode557. Reverse Words in a String III
- 15.leetCode557: Reverse Words in a String III
- [leetcode: Python]557. Reverse Words in a String III
- leetcode Reverse Words in a String III python解法
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- leetocde557: Reverse Words in a String III
- oj557. Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- codeforces 812E
- 蓝桥杯 数列排序
- JAVA_Web知识体系(浅入浅出)
- hihocoder1586-2017acm北京网络赛9&线段树&思维&板子- Minimum
- 用线段树求解坐标矩阵中的交并集面积思路及其模板代码
- python--leetcode557. Reverse Words in a String III
- 数值的整数次方
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛:Frequent Subsets Problem
- 决策树
- CentOS7好用么?
- 学习spark ml源码——线性回归
- SpringMVC同时使用<mvc:resources … />和日期转换Formatter时出现问题的解决方法
- HQL动态,分页查询及关联查询多对一单向
- OPC