Java Coding Challenge #001 - Finding maximum number in array recursively

preview_player
Показать описание
Can you solve the following coding challenge:
Find the largest number in an array of integers and do so by using a recursive function in Java.

If you either have no idea how to do it, you would like to see how you can check your solution or you would like to compare your solution to mine, this video is for you.
Hope you enjoy.

Feel free to leave a comment.

You can also reach me via twitter:
Рекомендации по теме
Комментарии
Автор

Starts at 10min for those wondering. The rest is more of a lesson on tests.

altimmons
Автор

I'm doing Ocaml these days so here is what the same code would look like in a functional programming language:


let find_max array =
let rec find_max_recursive rec_array acc =
match rec_array with
|[ ] -> acc
|hd::tail ->
if hd > acc then find_max_recursive tail hd
else find_max_recursive tail acc
in
find_max_recursive array -1

deeplearningexplained
Автор

Here is my Recursive solution in kotlin
maximum(intArrayOf(1, 2, 3, 5, 4), 5, 0)
private fun maximum(nums: IntArray, n: Int, max: Int): Int{
if(n == 0)
return max
return maximum(nums, n-1, Math.max(nums[n-1], max))


}

mramit
join shbcf.ru