easy +10 pts

Max of a variable-length list

Find the largest integer in a list without using built-in max().

Write a function `find_max(numbers)` that takes a list of integers and returns the largest integer in the list. If the list is empty, return `None`. You may not use the built-in `max()` function, but you can use any other Python features.

Constraints

Input is a list of integers. The list length is between 0 and 10^5. Each integer fits in a normal Python int.

Example

>>> find_max([3, 7, 2, 8, 5])
8
>>> find_max([-1, -5, -2])
-1
>>> find_max([])
None
10 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Initialize a variable to track the maximum seen so far. What initial value works for an empty list?
Loop through each number and update the maximum when you find a larger one.
Handle the empty list specially by returning None after the loop.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.