Skip to content

Commit 4c308b6

Browse files
committed
Time: 5212 ms (5.23%), Space: 18 MB (26.16%) - LeetHub
1 parent 72a4f22 commit 4c308b6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# time complexity: O(C - n)
2+
# space complexity: O(1)
3+
from typing import Counter
4+
5+
6+
class Solution:
7+
def nextBeautifulNumber(self, n: int) -> int:
8+
for i in range(n + 1, 1224445):
9+
count = Counter(str(i))
10+
if all(count[d] == int(d) for d in count):
11+
return i
12+
13+
14+
n = 1
15+
print(Solution().nextBeautifulNumber(n))
16+
n = 1000
17+
print(Solution().nextBeautifulNumber(n))
18+
n = 3000
19+
print(Solution().nextBeautifulNumber(n))

0 commit comments

Comments
 (0)