(String)151. Reverse Words in a String
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue",
return "blue is sky the".
public class Solution {
public String reverseWords(String s) {
String afterTrim= s.trim();
String[] split=afterTrim.split(" +"); //注意res
StringBuilder sb= new StringBuilder();
for(int i=split.length-1;i>=0;i--){
sb.append(split[i]+" ");
}
return sb.toString().trim();
}
}
(String)151. Reverse Words in a String的更多相关文章
- leetcode 557. Reverse Words in a String III 、151. Reverse Words in a String
557. Reverse Words in a String III 最简单的把空白之间的词反转 class Solution { public: string reverseWords(string ...
- 151. Reverse Words in a String(java 注意细节处理)
题目:reverse words in a string Given an input string, reverse the string word by word. For example,Giv ...
- 151 Reverse Words in a String 翻转字符串里的单词
给定一个字符串,翻转字符串中的每个单词.例如,给定 s = "the sky is blue",返回 "blue is sky the".对于C程序员:请尝试用 ...
- [LeetCode] 151. Reverse Words in a String 翻转字符串中的单词
Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...
- 【刷题-LeetCode】151 Reverse Words in a String
Reverse Words in a String Given an input string, reverse the string word by word. Example 1: Input: ...
- Reverse Words in a String I & Reverse Words in a String II
Reverse Words in a String I Given an input string, reverse the string word by word. For example,Give ...
- Java for LeetCode 151 Reverse Words in a String
Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...
- leetcode 151. Reverse Words in a String --------- java
Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...
- 151. Reverse Words in a String
Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...
随机推荐
- Xcode6.1标准Framework静态库制作方法。工程转Framework,静态库加xib和图片。完美解决方案。
http://www.cocoachina.com/bbs/read.php?tid-282490.html Xcode6.1标准Framework静态库制作方法.工程转Framework,静态库加x ...
- 计算机网络(7)-----TCP协议概述
传输控制协议(Transmission Control Protocol) 概念 一种面向连接的.可靠的.基于字节流的传输层通信协议,由IETF的RFC 793定义.在简化的计算机网络OSI模型中,它 ...
- 转载:ODS简介
什么是ODS? 信息处理的多层次要求导致了一种新的数据环境——DB-DW的中间层ODS(操作型数据存储)的出现.ODS是“面向主题的.集成的.当前或接近当前的.不断变化的”数据.通过统一规划,规范框架 ...
- 浅析Hadoop文件格式
Hadoop 作为MR 的开源实现,一直以动态运行解析文件格式并获得比MPP数据库快上几倍的装载速度为优势.不过,MPP数据库社区也一直批评Hadoop由于文件格式并非为特定目的而建,因此序列化和反序 ...
- 记录一些容易忘记的属性 -- UITabBarController
UIViewController中的 @property(nonatomic,copy) NSString *title; // Localized title for use by a pare ...
- IOS_画图 图片等比压缩 IOS_UIImage
- (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{ // 创建一个bitmap的context // 并把它设置成为当前正在使用的co ...
- WPF学习笔记——认识XAML
Extensible Application Markup Language,XAML是一种声明性标记语言. 一.XAML语法概述 1,与XML类似,用尖括号标记元素 <StackPanel&g ...
- 收到远程通知,怎么区分是点击通知栏提醒进去的还是在foreground收到的通知?
我现在是要区分点击通知栏的通知进入应用还是点击应用图标进入的,1,开始程序都是在后台.2,接受通知都是在foreground状态.applicationdidFinishLaunchWithOptio ...
- Javascript DOM基础(二) childNodes、children
childNodes知识点: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Typ ...
- CSS3 里添加自定义字体
添加自定义字体是从 CSS3 开始的,下载到的字体可以在网页中使用. 下载字体 在网上找字体下载,文件后缀名有 ttf.otf 等. 在 CSS 里加载字体 @font-face { font-fam ...