You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Brute-force all initial number lengths. For each number, we check if its equal to the previous one minus one, and then we jump to the next number. If the current number is a power of ten, we need to reduce the size of the next number by one (except for one and zero).
"""
from math import log
class Solution:
def solve(self, s):
def dfs(i,j,prev):
if i>=len(s): return True
cur=s[i:j]
cur_num=int(cur)
if prev is not None and cur_num != prev-1: return False
ni = j
nj = ni+len(cur)
if cur_num not in (1,0) and log(cur_num,10).is_integer():