|
| 1 | +''' |
| 2 | +You are given an integer array digits, where each element is a digit. The array may contain duplicates. |
| 3 | + |
| 4 | +You need to find all the unique integers that follow the given requirements: |
| 5 | + |
| 6 | +The integer consists of the concatenation of three elements from digits in any arbitrary order. |
| 7 | +The integer does not have leading zeros. |
| 8 | +The integer is even. |
| 9 | +For example, if the given digits were [1, 2, 3], integers 132 and 312 follow the requirements. |
| 10 | + |
| 11 | +Return a sorted array of the unique integers. |
| 12 | +''' |
| 13 | + |
| 14 | + |
| 15 | +class Solution: |
| 16 | + def findEvenNumbers(self, digits: List[int]) -> List[int]: |
| 17 | + res = set() |
| 18 | + n = len(digits) |
| 19 | + freq = dict(Counter(digits)) |
| 20 | + for i in range(100,1000,2): |
| 21 | + |
| 22 | + cur = list(map(int, str(i))) |
| 23 | + |
| 24 | + fr2 = dict(Counter(cur)) |
| 25 | + st = True |
| 26 | + for k,v in fr2.items(): |
| 27 | + |
| 28 | + if k not in freq or freq[k] < v: |
| 29 | + st = False |
| 30 | + break |
| 31 | + if st: |
| 32 | + res.add(i) |
| 33 | + |
| 34 | + res = sorted(list(res)) |
| 35 | + return res |
0 commit comments