Skip to content

Commit e508c59

Browse files
committed
Sync LeetCode submission Runtime - 2705 ms (27.11%), Memory - 18.1 MB (28.25%)
1 parent 104c80f commit e508c59

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<p>You are given an integer array <code>digits</code>, where each element is a digit. The array may contain duplicates.</p>
2+
3+
<p>You need to find <strong>all</strong> the <strong>unique</strong> integers that follow the given requirements:</p>
4+
5+
<ul>
6+
<li>The integer consists of the <strong>concatenation</strong> of <strong>three</strong> elements from <code>digits</code> in <strong>any</strong> arbitrary order.</li>
7+
<li>The integer does not have <strong>leading zeros</strong>.</li>
8+
<li>The integer is <strong>even</strong>.</li>
9+
</ul>
10+
11+
<p>For example, if the given <code>digits</code> were <code>[1, 2, 3]</code>, integers <code>132</code> and <code>312</code> follow the requirements.</p>
12+
13+
<p>Return <em>a <strong>sorted</strong> array of the unique integers.</em></p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong class="example">Example 1:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> digits = [2,1,3,0]
20+
<strong>Output:</strong> [102,120,130,132,210,230,302,310,312,320]
21+
<strong>Explanation:</strong> All the possible integers that follow the requirements are in the output array.
22+
Notice that there are no <strong>odd</strong> integers or integers with <strong>leading zeros</strong>.
23+
</pre>
24+
25+
<p><strong class="example">Example 2:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> digits = [2,2,8,8,2]
29+
<strong>Output:</strong> [222,228,282,288,822,828,882]
30+
<strong>Explanation:</strong> The same digit can be used as many times as it appears in digits.
31+
In this example, the digit 8 is used twice each time in 288, 828, and 882.
32+
</pre>
33+
34+
<p><strong class="example">Example 3:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> digits = [3,7,5]
38+
<strong>Output:</strong> []
39+
<strong>Explanation:</strong> No <strong>even</strong> integers can be formed using the given digits.
40+
</pre>
41+
42+
<p>&nbsp;</p>
43+
<p><strong>Constraints:</strong></p>
44+
45+
<ul>
46+
<li><code>3 &lt;= digits.length &lt;= 100</code></li>
47+
<li><code>0 &lt;= digits[i] &lt;= 9</code></li>
48+
</ul>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution:
2+
def findEvenNumbers(self, digits: List[int]) -> List[int]:
3+
result = set()
4+
n = len(digits)
5+
6+
for i in range(n):
7+
# Skip if first digit is 0
8+
if digits[i] == 0:
9+
continue
10+
11+
for j in range(n):
12+
# Skip same index
13+
if i == j:
14+
continue
15+
16+
for k in range(n):
17+
# Skip same index
18+
if k == i or k == j:
19+
continue
20+
21+
num = digits[i] * 100 + digits[j] * 10 + digits[k]
22+
23+
if num % 2 == 0:
24+
result.add(num)
25+
26+
return sorted(list(result))

0 commit comments

Comments
 (0)