2542. Average Value of Even Numbers That Are Divisible by Three
My accepted Python solution to LeetCode problem 2542, Average Value of Even Numbers That Are Divisible by Three, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 17.4MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.4MB, accepted 2026-01-01.
class Solution:
def averageValue(self, nums: List[int]) -> int:
# Even and divisible by 3 means divisible by 6
valid = [n for n in nums if n % 6 == 0]
return sum(valid) // len(valid) if valid else 0