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. hdu 4635 Strongly connected

    http://acm.hdu.edu.cn/showproblem.php?pid=4635 我们把缩点后的新图(实际编码中可以不建新图 只是为了概念上好理解)中的每一个点都赋一个值 表示是由多少个点 ...

  2. sourceTree 更新svn提示can't locate SVN/Core.pm

    装了sourceTree一直没有怎么用,今天试着用用,居然报错 can't locate SVN/Core.pm 详细报错如下: Can't locate SVN/Core.pm in @INC (y ...

  3. linux命令每日一练习-mkdir,rm

    mkdir 创建一个文件夹 mkdir -p tian/hong 递归创建文件目录 mkdir tian hong 创建多个文件 mkdir -v tian 创建文件的时候显示信息 mkdir -m ...

  4. autotools工具使用记录

    参考 http://blog.chinaunix.net/uid-25100840-id-271131.html http://blog.sina.com.cn/s/blog_4c2bf01a0101 ...

  5. JVM-并发-线程

    线程 1.线程的实现 (1)实现线程主要有3中方式:使用内核线程实现,使用用户线程实现和使用用户线程加轻量级进程混合实现. (2)使用内核线程实现 内核线程就是直接由操作系统内核支持的线程,这种线程由 ...

  6. android技巧(一):如何方便知晓当前Activity?如何管理应用中的Activity?如何最佳的启动一个Activity?

    1.如何方便知晓当前Activity? 可以不看代码根据当前界面就知道界面所在Activity的写法: 建立BaseActivity,继承自Activity,在BaseActivity的OnCreat ...

  7. Brief Tour of the Standard Library

    10.1. Operating System Interface The os module provides dozens of functions for interacting with the ...

  8. 从c开始,小小感悟

    c语言是众多编程小白进入编程大门的钥匙,不过许多人在学习一段时间以后就渐渐产生了困惑,枯燥的黑色界面渐渐让他们失去了"渴望",---我还不能制作出一款像样的软件,我还是只是在算数学 ...

  9. 复健小CM

    系统 : Windows xp 程序 : Keygenme # 2 程序下载地址 :http://pan.baidu.com/s/1qYIk2HQ 要求 : 注册机编写 使用工具 : OD 可在“PE ...

  10. asp.net 发布后,遇到的导出excel报错的问题

    做的asp.net程序,最近要发布在外网上,发布过程不太难,网上都有现成的,只要按照相应的步骤基本都不会有什么问题,关键是发布成功后,程序中涉及到excel的导出或者导入问题,就会提示“检索COM 类 ...