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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 151 Reverse Words in a String 翻转字符串里的单词

    给定一个字符串,翻转字符串中的每个单词.例如,给定 s = "the sky is blue",返回 "blue is sky the".对于C程序员:请尝试用 ...

  4. [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& ...

  5. 【刷题-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: ...

  6. 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 ...

  7. 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 ...

  8. 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& ...

  9. 151. Reverse Words in a String

    Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...

随机推荐

  1. cocos2d-x 中的坐标系

    cocos2d-x 中的坐标系是笛卡尔坐标系,向右为 x 轴正方向,向上为 y 轴正方向,以像素为单位 原点在屏幕左下角的坐标系叫世界坐标系,是整个游戏中的根基,直接添加到场景中的节点,设置的位置都是 ...

  2. BestCoder Round #40

    T1:Tom and pape (hdu 5224) 题目大意: 给出一个矩形面积N,求周长的最小值.(长&&宽&&面积都是正整数) N<=109 题解: 没啥好 ...

  3. Java设计模式系列1--原型模式(Prototype Method)

    2014-02-14 11:27:33 声明:本文不仅是本人自己的成果,有些东西取自网上各位大神的思想,虽不能一一列出,但在此一并感谢! 原型模式,从名字即可看出,该模式的思想就是将一个对象作为原型, ...

  4. SSH(2)

    1.用户登录 index页面跳转到登录页面 <% String path = request.getContextPath(); String basePath = request.getSch ...

  5. Android 绿豆蛙版连连看(简陋版)

    (里面有六张绿豆蛙的图片) 1.选中会有红色框 2.可以直线连(横竖相邻或是横竖间隔空格) 3.可以拐一次弯连接 4.可以拐两次弯连接 5.连接时会有线显示 6.绿色代表进度条,蓝色代表时间条 imp ...

  6. candence 知识积累3

    1. PCB板型: 1.新建PCB:PCB design ,新建的类型为board ,输入名称和保存位置,设置图纸参数.网格参数. 2.建立PCB板外框:菜单Add下选择相应的工具.在Option选项 ...

  7. JavaScript基础--DOM对象加强篇(十四)

    1.document 对象 定义:document对象代表的整个html文档,因此可以去访问到文档中的各个对象(元素)document重要的函数 1.1 write 向文档输出文本或js代码 1.2 ...

  8. (转)PhoneGap工作原理及需改进的地方

    原文:http://mobile.51cto.com/web-330900.htm PhoneGap工作原理及需改进的地方 2012-04-18 16:42 佚名 网络整理 字号:T | T 目前开发 ...

  9. hdu 2059

    ps:终于解决了....卡了我好久.最后用了DP.然后还有记忆化搜索优化了一下.终于AC了 思路:要计算dp[n](就是到第n个站的最短时间,也就是最优方案),必须知道dp[0]到dp[n-1] 设j ...

  10. 关于ASP.NET页面打印技术的总结【转】

    B/S结构导致了Web应用程序中打印的特殊性. • 程序运行在浏览器中,打印机在本地,而文件确可能在服务器上,导致了打印控制不是很灵活. • 格式如何控制和定制等,是我们开发中可能会面对的问题. 打印 ...