Skip to content

Instantly share code, notes, and snippets.

@kanrourou
Created December 20, 2014 23:51
Show Gist options
  • Save kanrourou/0bf5238577f20062e09d to your computer and use it in GitHub Desktop.
Save kanrourou/0bf5238577f20062e09d to your computer and use it in GitHub Desktop.
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