This commit is contained in:
parent
5dfd6029bd
commit
accdb52aec
1 changed files with 36 additions and 0 deletions
36
easy/finding_3_digit_even_numbers.py
Normal file
36
easy/finding_3_digit_even_numbers.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# https://leetcode.com/problems/finding-3-digit-even-numbers
|
||||
|
||||
from typing import List
|
||||
|
||||
class Solution:
|
||||
def findEvenNumbers(self, digits: List[int]) -> List[int]:
|
||||
counts = [0] * 10
|
||||
for digit in digits:
|
||||
counts[digit] += 1
|
||||
answer = []
|
||||
i = 0
|
||||
while i < 10:
|
||||
if i == 0 or counts[i] == 0:
|
||||
i += 1
|
||||
continue
|
||||
counts[i] -= 1
|
||||
j = 0
|
||||
while j < 10:
|
||||
if counts[j] == 0:
|
||||
j += 1
|
||||
continue
|
||||
counts[j] -= 1
|
||||
k = 0
|
||||
while k < 10:
|
||||
if counts[k] == 0:
|
||||
k += 1
|
||||
continue
|
||||
if k % 2 == 0:
|
||||
answer.append(i * 100 + j * 10 + k)
|
||||
k += 1
|
||||
counts[j] += 1
|
||||
j += 1
|
||||
counts[i] += 1
|
||||
i += 1
|
||||
return answer
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue