(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& ...
随机推荐
- redis服务和扩展安装(windows)
Windows下安装redis和在php中使用phpredis扩展 原文地址:http://m.oschina.net/blog/281058 Junn 发布于 2年前,共有 0 条评论 1.redi ...
- 关于ADDED_TO_STAGE事件
可视类初始化的时候,很多时候要用到stage属性,则要使用Event.ADDED_TO_STAGE事件,这个swf被其它的文件加载,如果直接在初始化函数内使用stage属性 .但是,文档类初始化函数内 ...
- C#学习笔记----枚举、结构、方法及构造函数的总结
一.枚举 语法: [public] enum 枚举名 { 值1, 值2, 值3, ........ } public:访问修饰符.公开的公共的,哪都可以访问. enum:关键字,声明枚举的关键字 枚举 ...
- MYSQL中关于日期处理的函数
< DOCTYPE HTML PUBLIC -WCDTD HTML TransitionalEN> MySQL数据库中SQL语句中 关于日期.时间\时间戳的函数 一 MySQL 获得当 ...
- Xcode5 取消ARC
终于开心的装上Xcode5,主管马上发布新的任务,开始新的项目,各种开心,终于可以换个界面看看了. 可是谁知第一步创建项目就开始悲剧了,居然没有地方可以选择非ARC了,真是肿么个情况呀,查了一下,万能 ...
- swift objective-及c语言 混编
在xocde6出来我们大部分代码都是用objective-c写的(部分C/C++),现在出生来了一个新的语言叫swift,那么如何既能使用我们之前的代码,还可以使用新语言呢, 本文就此做一下说明. 关 ...
- HDU 3555 Bomb
RT. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...
- 第三个Sprint冲刺第二天
讨论地点:宿舍 讨论成员:邵家文.李新.朱浩龙.陈俊金 讨论问题:强化答案讲解功能
- KVC/KVO原理详解及编程指南
一.简介 1.KVC简介 2.KVO简介 二.KVC相关技术 1.Key和Key Path 2.点语法和KVC 3.一对多关系(To-Many)中的集合访问器方法 4.键值验证(Key-Value V ...
- Python开发库
在我多年的 Python 编程经历以及在 Github 上的探索漫游过程中,我发掘到一些很不错的 Python 开发包,这些包大大简化了开发过程,而本文就是为了向大家推荐这些开发包. 请注意我特别排除 ...