Algorithms/Find maximum/Python method 2
Appearance
Python (2.6) source code.
def findMax(a):
length = len(a)
if length == 0 :
return 0
elif length == 1 :
return a[0]
elif length == 2 :
if a[0] > a[1] :
return a[0]
else :
return a[1]
half = length / 2
list_A = a[:half]
list_B = a[half:]
max_A = findMax(list_A)
max_B = findMax(list_B)
if max_A > max_B :
return max_A
else :
return max_B