Leetcode: Reverse Words in a String
来源:互联网 发布:网络小说推荐 知乎 编辑:程序博客网 时间:2024/05/15 11:01
Question
Given an input string, reverse the string word by word.
For example,
Given s = “the sky is blue”,
return “blue is sky the”.
Update (2015-02-12):
For C programmers: Try to solve it in-place in O(1) space.
click to show clarification.
Clarification:
What constitutes a word?
A sequence of non-space characters constitutes a word.
Could the input string contain leading or trailing spaces?
Yes. However, your reversed string should not contain leading or trailing spaces.
How about multiple spaces between two words?
Reduce them to a single space in the reversed string.
Hide Tags String
Hide Similar Problems (M) Reverse Words in a String II
Solution
class Solution(object): def reverseWords(self, s): """ :type s: str :rtype: str """ return ' '.join(s.split()[::-1])
0 0
- Leetcode - string - Reverse Words in a String
- Reverse words in a String leetcode
- [LeetCode]Reverse Words in a String
- 【LeetCode】Reverse Words in a String
- Reverse Words in a String (LeetCode)
- LeetCode Reverse Words in a String Total
- LeetCode(151)Reverse Words in a String
- Reverse Words in a String -- LeetCode
- leetcode Reverse Words in a String
- LeetCode OJ:Reverse Words in a String
- LeetCode Reverse Words in a String
- 【LeetCode】Reverse Words in a String
- [Leetcode] Reverse Words in a String
- Reverse Words in a String[LeetCode]
- LeetCode OJ :Reverse Words in a String
- Leetcode: Reverse Words in a String
- 【LeetCode】Reverse Words in a String
- 【LeetCode】Reverse Words in a String
- xml
- Linux内核编程的特点
- 使用GDI+和CImage类加载png图片
- typedef用途
- YARN源码分析(四)-----Journalnode
- Leetcode: Reverse Words in a String
- Nginx学习笔记一_UNIX中的IO模型
- MVCC实现-MYSQL INNODB MVCC实现
- GBK和UTF8的区别,该选择哪个版本
- lintcode-数字组合-135
- [LeetCode 200] Number of Islands
- java-接口List-Map
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- 关于多态的问题