【编程】【leetcode】151. Reverse Words in a String
来源:互联网 发布:sql 试图 编辑:程序博客网 时间:2024/06/05 11:04
/** \\d表示 0-9 的数字, \\s表示 空格,回车,换行等空白符, \\w表示单词字符(数字字母下划线) +号表示一个或多个 * */ class Solution { public String reverseWords(String s) { String[] parts = s.trim().split("\\s+"); String out = ""; for (int i = parts.length - 1; i > 0; i--) { out += parts[i] + " "; } return out + parts[0]; } }
public class Solution { public String reverseWords(String s) { String[] words = s.trim().split(" +"); Collections.reverse(Arrays.asList(words)); return String.join(" ", words); }}
http://www.cnblogs.com/grandyang/p/4606676.html
0 0
- 【编程】【leetcode】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
- [leetcode] 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
- LeetCode 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
- leetcode 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
- leetcode 151. Reverse Words in a String
- [LeetCode] 151. Reverse Words in a String
- 利用python的生成器解决八皇后问题
- 腾讯大咖说:腾讯是如何做Unity手游性能优化的
- 寄存器寻址
- Error:Application and test application id cannot be the same: both are 'com.xxxxxxx' for debugAndroi
- vs2017离线安装并且安装包不占用C盘空间
- 【编程】【leetcode】151. Reverse Words in a String
- codeforces 792A
- 单例模式
- 遗传算法入门到掌握(一)
- [译] Deep Residual Learning for Image Recognition (ResNet)
- Oracle(10)查询语句
- Struts2对值栈中的List便利,格式都正确却遍历不出来数据的问题
- 【C++】Vs2008环境下安装编译boost库
- Android广播接收者详解