Middle-题目126：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) {
s=s.trim();
String[] words = s.split(" ");
String result = "";
for(int i = words.length-1;i>0;i--) {
if(!words[i].equals(""))
result=result+words[i]+" ";
}
if(words.length!=0)
result+=words[0];
return result;
}
}

58ms,beats 8.93%,众数3ms,13.42%
Cmershen的碎碎念：

[leetcode] 151. Reverse Words in a String 解题报告

2016-01-18 14:40:11

Leetcode 第151题 最新题解 Reverse Words in a String

2014-03-07 12:13:26

LeetCode(151)Reverse Words in a String

2014-03-10 02:47:53

LeetCodeOJ--Reverse Words in a String(python版本)

2014-06-09 11:09:44

【LeetCode刷题Java版】Reverse Words in a String

2014-10-13 14:21:21

leetcode 151 Reverse Words in a String java 算法

2016-07-20 19:37:08

python：leetcode之reverse words in a string

2016-02-21 17:30:27

leetcode-java-151. Reverse Words in a String

2016-06-29 09:46:37

leetcode151-Reverse Words in a String(翻转字符串单词的位置)

2016-04-03 11:21:01

[LeetCode]557. Reverse Words in a String III(反转字符串 III)

2017-04-10 00:46:36

不良信息举报

Middle-题目126：151. Reverse Words in a String