From 3ed50368133c7099924360b5e6a758054c0b3378 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Mon, 12 May 2025 00:31:34 -0600 Subject: 2094. finding 3 digit event numbers --- finding_3_digit_even_num.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 finding_3_digit_even_num.py (limited to 'finding_3_digit_even_num.py') diff --git a/finding_3_digit_even_num.py b/finding_3_digit_even_num.py new file mode 100644 index 0000000..cf6ccc7 --- /dev/null +++ b/finding_3_digit_even_num.py @@ -0,0 +1,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])) -- cgit v1.2.3