Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bfea5b0

Browse files
authored
Create Finding 3-Digit Even Numbers.py
1 parent 1985b19 commit bfea5b0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

‎Finding 3-Digit Even Numbers.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /