2174. Next Greater Numerically Balanced Number
My accepted Python solution to LeetCode problem 2174, Next Greater Numerically Balanced Number, running in 4523ms.
- Difficulty: Medium
- Python
- Runtime 4523ms
- Memory 17.4MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 4523ms, memory 17.4MB, accepted 2025-12-29.
class Solution:
def nextBeautifulNumber(self, n: int) -> int:
def isBalanced(num):
s = str(num)
from collections import Counter
cnt = Counter(s)
for digit, count in cnt.items():
if int(digit) != count:
return False
return True
num = n + 1
while not isBalanced(num):
num += 1
return num