LeetCode:Reverse Words in a String
来源:互联网 发布:java消息服务器怎么写 编辑:程序博客网 时间:2024/06/05 19:26
Reverse Words in a String
Total Accepted: 102953 Total Submissions: 655369 Difficulty: Medium
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
Hide Similar Problems
思路:
s中两边可能有空格,单词之间可能有多个空格,这些都需要去掉。
用正则表达式就是爽~~~
java code:
public class Solution { public String reverseWords(String s) { String[] strs = s.trim().split("\\s+"); String ans = ""; for(int i=strs.length-1;i>=0;i--) { if(i!=0) ans += strs[i]+" "; else ans += strs[i]; } return ans; }}
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
- 特性值长文本函数读取的用法(BAPI_CHARACT_GETLONGTEXT)
- iOS开发 UICollectionView属性介绍
- android studio 使用快捷键
- su: Authentication failure
- Object类
- LeetCode:Reverse Words in a String
- iOS使其支持侧滑返回
- 看了《spring技术内幕》简单的图解总结下spring一些请求调用流程
- 5.JVM三大性能调优参数:-Xms -Xmx -Xss
- 矩阵分析与应用
- 对博客的自我感觉
- Jquery ajax 学习记录
- 友盟 集成新浪微博的坑
- 结构化 数据库 代码