Created
July 28, 2022 05:47
-
-
Save ioanzicu/0574520d09e4d7f486108c51e864b679 to your computer and use it in GitHub Desktop.
Find the maximum value element in a list recursively in Python 3.
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
def find_max(nums): | |
if not nums: | |
return 0 | |
return max(nums[0], find_max(nums[1:])) | |
nums = [1, 2, 3, 4, 5] | |
print(find_max(nums)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment