Skip to content

Instantly share code, notes, and snippets.

@bchetty
Created May 23, 2013 22:48
Show Gist options
  • Save bchetty/5640072 to your computer and use it in GitHub Desktop.
Save bchetty/5640072 to your computer and use it in GitHub Desktop.
Reverse Words - GCJ 2010 (Africa)
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