151. Reverse Words in a String
来源:互联网 发布:淘宝代刷销量平台 编辑:程序博客网 时间:2024/04/28 15:55
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.
Subscribe to see which companies asked this question
分析:
代码:
class Solution(object):
def reverseWords(self, s):
"""
:type s: str
:rtype: str
"""
s=s.strip()
if not s:
return s
s1=s.split(" ")
b=[]
for temp in s1:
if temp!="":
b.append(temp)
b=b[::-1]
s2=" ".join(b)
return s2
0 0
- LeetCode 151. Reverse Words in a String
- LeetCode 151. Reverse Words in a String
- [LeetCode]151.Reverse Words in a String
- 151. Reverse Words in a String
- [leetcode] 151.Reverse Words in a String
- Leetcode-151.Reverse Words in a String
- Leetcode 151. Reverse Words in a String
- 151. Reverse Words in a String
- 151. Reverse Words in a String
- 151. Reverse Words in a String
- [leetcode]151. Reverse Words in a String
- 151. Reverse Words in a String
- 151. Reverse Words in a String
- LeetCode 151. Reverse Words in a String
- Leetcode 151. Reverse Words in a String
- 151. Reverse Words in a String
- LeetCode *** 151. Reverse Words in a String
- LeetCode-151.Reverse Words in a String
- 恢复博客更新
- STL中list的重写
- Oracle里,scope=both或者scop=pfile这个选项是做什么用的
- android:windowSoftInputMode属性
- 求解物体重心
- 151. Reverse Words in a String
- Spring读书笔记-----部署我的第一个Spring项目
- spring面试题
- 《了不起的盖茨比》有感
- Bean
- [DELVE][web]基于angular js的Spring security验证
- Udp投票通信例子
- Spring 读书笔记-----使用Spring容器(一)
- Matlab 存储图片