Skip to content

Instantly share code, notes, and snippets.

@shenie
Created January 29, 2010 20:08
Show Gist options
  • Save shenie/290064 to your computer and use it in GitHub Desktop.
Save shenie/290064 to your computer and use it in GitHub Desktop.
dhanji take 2
public void _glom(Stack<String> stack, String...a) {
if (a.length == 0) {
if (stack.peek() == "") {
stack.pop();
}
return;
}
String s = a[0];
if (s != "") {
stack.push(stack.pop() + s);
} else {
if (stack.peek() != "") {
stack.push("");
}
}
_glom(stack, Arrays.copyOfRange(a, 1, a.length));
}
public List<String> glom(String...a) {
Stack<String> stack = new Stack<String>();
stack.push("");
_glom(stack, a);
return Arrays.asList(stack.toArray(new String[stack.size()]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment