public class Solution {
/*
* @param s: A string
* @return: A string
*/
public static String reverseWords(String s) {
if(s==null || s.length() == 0) return "";
String[] array = s.split(" ");
StringBuilder sb = new StringBuilder();
for (int i = array.length - 1; i>=0; --i) {
if(!array[i].equals("")){
sb.append(array[i]).append(" ");
}
}
return sb.toString();
}
}

LintCode 53---翻转字符串中的单词的更多相关文章

  1. [LeetCode] Reverse Words in a String 翻转字符串中的单词

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

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

  3. [LeetCode] 186. Reverse Words in a String II 翻转字符串中的单词 II

    Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...

  4. [LeetCode] 557. Reverse Words in a String III 翻转字符串中的单词 III

    Given a string, you need to reverse the order of characters in each word within a sentence while sti ...

  5. [LeetCode] Reverse Words in a String II 翻转字符串中的单词之二

    Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...

  6. [LeetCode] Reverse Words in a String III 翻转字符串中的单词之三

    Given a string, you need to reverse the order of characters in each word within a sentence while sti ...

  7. LeetCode刷题:Reverse Words in a String(翻转字符串中的单词)

    题目 Given an input string, reverse the string word by word. For example, Given s = "the sky is b ...

  8. [LintCode] Reverse Words in a String 翻转字符串中的单词

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

  9. [Swift]LeetCode186. 翻转字符串中的单词 II $ Reverse Words in a String II

    Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...

  10. java翻转字符串中的单词

    效果: 输入: "java and python" 输出: "avaj dna nohtyp" 代码: 版本1: 不考虑字符串开头有空格,单词间有多个空格空格的 ...

随机推荐

  1. 读取天气信息,并通过QQ邮箱发送至指定邮箱

    from email.mime.text import MIMEText from email.header import Header from smtplib import SMTP_SSL im ...

  2. spark streaming 4: DStreamGraph JobScheduler

    DStreamGraph有点像简洁版的DAG scheduler,负责根据某个时间间隔生成一序列JobSet,以及按照依赖关系序列化.这个类的inputStream和outputStream是最重要的 ...

  3. jxbrowser java代码直接调用js代码

    https://blog.csdn.net/shuaizai88/article/details/73743669 final Browser browser = new Browser(); Bro ...

  4. 图片加载框架之fresco

    FaceBook推出的图片处理框架主页: https://github.com/facebook/fresco中文文档:http://fresco-cn.org/docs/index.html 功能 ...

  5. Failed to install the following Android SDK packages as some licences have not been accepted.

    问题描述: 执行gradle tasks报错: gradle tasks > Configure project :app Exception /package.xml. Probably th ...

  6. Gradle DSL method not found: 'compile()'

    问题描述: 今天在导入第三方库的时候报错:Gradle DSL method not found: 'compile()' 通过网上查询发现是自己导包路径错误:应该导入app下面的build.grad ...

  7. CodeForces 1249A --- Yet Another Dividing into Teams

    [CodeForces 1249A --- Yet Another Dividing into Teams] Description You are a coach of a group consis ...

  8. 从STL文件到网格拓扑

    原文链接 STL文件是什么 STL文件是网格文件的一种格式,分为二进制和文本两种类型.具体来讲,它定义了一群三角面片,比如下面是一个文本的STL示例: solid geometryplusplus f ...

  9. numpy的divide函数

    和直接用/一样,都是矩阵的对应元素相除. 如果用*,那么是矩阵的对应元素相乘. 如果要实现矩阵乘法,用numpy的dot函数.

  10. 华为HCNA乱学Round 10:PPP&PAP