Created
December 20, 2014 23:51
-
-
Save kanrourou/0bf5238577f20062e09d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public String reverseWords(String s) { | |
if (s == null) | |
return ""; | |
String res = ""; | |
int len = s.length(); | |
for (int i = 0; i < len;) { | |
String temp = ""; | |
while (i < len && s.charAt(i) == ' ') | |
i++; | |
if (i == len) | |
break; | |
while (i < len && s.charAt(i) != ' ') | |
temp += s.charAt(i++); | |
res = res.length() == 0? temp: temp + " " + res; | |
} | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment