From f6cd99c88be4aa19fd761b880f8e9353d4bf9092 Mon Sep 17 00:00:00 2001 From: k1borgG <69363313+k1borgG@users.noreply.github.com> Date: Wed, 19 Jul 2023 18:51:46 +0300 Subject: [PATCH] Create 04_recursive_max.py (#249) Problem with max definition. If in input list last element is the biggest, the present algorithm is'n count it. I solved this problem by changing the return in the case if length == 1 from return 1 to first element of list. --- 04_quicksort/python/04_recursive_max.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/04_quicksort/python/04_recursive_max.py b/04_quicksort/python/04_recursive_max.py index 908c31a..717e4f9 100644 --- a/04_quicksort/python/04_recursive_max.py +++ b/04_quicksort/python/04_recursive_max.py @@ -1,8 +1,8 @@ -def max_(lst): - if len(lst) == 0: - return None - if len(lst) == 1: - return lst[0] - else: - sub_max = max_(lst[1:]) - return lst[0] if lst[0] > sub_max else sub_max +def max(lst): + if len(lst) == 0: + return None + if len(lst) == 1: + return lst[0] + else: + max_num = max(lst[1:]) + return lst[0] if lst[0] > max_num else max_num