diff options
author | Jack Sangdahl <[email protected]> | 2025-05-12 00:31:34 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-05-12 00:31:34 -0600 |
commit | 3ed50368133c7099924360b5e6a758054c0b3378 (patch) | |
tree | 44b647f9e19da0f906797d36a56fdc5d885e68c0 /finding_3_digit_even_num.py | |
parent | eee47c29b5dd2a152a3c898525b8871503625a3e (diff) | |
download | leetcode-3ed50368133c7099924360b5e6a758054c0b3378.tar.gz leetcode-3ed50368133c7099924360b5e6a758054c0b3378.zip |
2094. finding 3 digit event numbers
Diffstat (limited to 'finding_3_digit_even_num.py')
-rw-r--r-- | finding_3_digit_even_num.py | 32 |
1 files changed, 32 insertions, 0 deletions
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])) |