aboutsummaryrefslogtreecommitdiff
path: root/finding_3_digit_even_num.py
blob: cf6ccc703cd5f13f26ebbd9ec1eb9131d5d092b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 2094. Finding 3-Digit Even Numbers
from itertools import permutations

"""
you are given an integer 'digits' where each element is a digit. the array
may contain duplicates. you need to find all the unique integers that follow
the given requirements: the integer consists of the concatenation of three
elements from 'digits' in any arbitrary order, the integer does not have
leading zeros, and the integer is even. for example, if the given 'digits'
were '[1, 2, 3]' integers '132' and '312' follow the requirments. return a
sorted array of the unique integers.
"""


class Solution(object):
    def findEvenNumbers(self, digits):
        """
        :type digits: List[int]
        :rtype: List[int]
        """
        return sorted(
            100 * v + 10 * u + w
            for v, u, w in {*permutations(digits, 3)}
            if v > 0 == w & 1
        )


if __name__ == "__main__":
    obj = Solution()
    print(obj.findEvenNumbers(digits=[2, 1, 3, 0]))
    print(obj.findEvenNumbers(digits=[2, 2, 8, 8, 2]))
    print(obj.findEvenNumbers(digits=[3, 7, 5]))