mirror of
https://github.com/onyx-and-iris/grokking-algorithms.git
synced 2025-01-18 00:30:53 +00:00
add maximum
This commit is contained in:
parent
22545b8911
commit
fa3b3396f7
19
chapter4/maximum.py
Normal file
19
chapter4/maximum.py
Normal file
@ -0,0 +1,19 @@
|
||||
import logging
|
||||
import math
|
||||
import random
|
||||
|
||||
highest = math.inf
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def maximum(nums, size):
|
||||
if size == 1:
|
||||
return nums[0]
|
||||
return max(nums[size - 1], maximum(nums, size - 1))
|
||||
|
||||
|
||||
randomlist = random.sample(range(10, 300), 5)
|
||||
logger.debug(randomlist)
|
||||
print(maximum(randomlist, len(randomlist)))
|
Loading…
Reference in New Issue
Block a user