Skip to content

Instantly share code, notes, and snippets.

@tomgullo
Last active December 11, 2015 06:09
Show Gist options
  • Save tomgullo/4557629 to your computer and use it in GitHub Desktop.
Save tomgullo/4557629 to your computer and use it in GitHub Desktop.
get max using recursion
def getMax(List list, int max) {
/* TODO - error handling null values etc */
if (list.size() == 1) {
return (list[0] > max) ? list[0] : max
} else if ( list[0] > max) {
getMax(list[1..-1], list[0])
} else {
getMax(list[1..-1], max)
}
}
println getMax([1,3,8,4,7,3,4], 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment