Most frequent number
Write code · Challenge · §4.3 Counting occurrences
Complete the function solution, which returns the number that appears most often in the list of integers nums.
If more than one number appears most often, return the smallest of them.
Function
solution(nums)
Constraints
- The length of
numsis from 1 to 1,000. - Each element of
numsis an integer from -1,000,000 to 1,000,000.
Examples
| nums | result |
|---|---|
[5, 2, 5, 2, 9] | 2 |
[4] | 4 |
Starter code
def solution(nums):
answer = 0
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.