Finding 3-Digit Even Numbers LeetCode solution in Python

1
class Solution:
2
def findEvenNumbers(self, digits: List[int]) -> List[int]:
3
hmap, res = defaultdict(int), []
4
for num in digits:
5
hmap[num] += 1 # counting frequency of digits of digits array
6

7
for num in range(100, 999, 2): # step 2 because we need even numbers
8
checker = defaultdict(int)
9
for digit in str(num):
10
checker[int(digit)] += 1 # counting frequency of digits of num
11

12
# check if every digit in num is in digits array and its frequency is less than or equal to its frequency in digits array
13
if all(map(lambda x: x in hmap and checker[x] <= hmap[x], checker)):
14
res.append(num)
15

16
return res

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0