LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.4MB, accepted 2026-01-01.

python
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

Source