Skip to content

Instantly share code, notes, and snippets.

@cuongld2
Created November 3, 2020 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuongld2/795788a1e550e40f8352c7ec79f32980 to your computer and use it in GitHub Desktop.
Save cuongld2/795788a1e550e40f8352c7ec79f32980 to your computer and use it in GitHub Desktop.
max function recursive
def max(xs: List[Int]): Int = {
if (xs.isEmpty)
throw new NoSuchElementException
else if (xs.length == 1)
xs.head
else
if (xs.head > max(xs.tail)) xs.head else max(xs.tail)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment