Created
May 23, 2013 22:48
-
-
Save bchetty/5640072 to your computer and use it in GitHub Desktop.
Reverse Words - GCJ 2010 (Africa)
This file contains 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
import java.util.*; | |
import java.io.*; | |
public class ReverseWords { | |
public String reverseWords(String phrase) { | |
List<string> wordList = Arrays.asList(phrase.split("[ ]")); | |
Collections.reverse(wordList); | |
StringBuilder sbReverseString = new StringBuilder(); | |
for(String word: wordList) { | |
sbReverseString.append(word + " "); | |
} | |
return sbReverseString.substring(0, sbReverseString.length() - 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment