Created
June 3, 2020 09:03
-
-
Save bhaveshmunot1/28236e7e2a8ae51a9ee55d435b1d0b65 to your computer and use it in GitHub Desktop.
Find maximum number in an array using recursion.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int max_in_array(vector<int> nums, int start_index, int end_index) { | |
if (start_index == end_index) { | |
return nums[start_index]; | |
} | |
int maximum = max_in_array(nums, start_index+1, end_index); | |
return max(nums[start_index], maximum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment