Splitting a String Into Descending Consecutive Values

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class Solution:
    def splitString(self, s: str) -> bool:
        def check(s, i=0, prev=0):
            num = 0
            for j in range(i, len(s) - (1 if i == 0 else 0)):
                num = num * 10 + (ord(s[j]) - ord('0'))
                if num < 1e10 and (i == 0 or prev - 1 == num) and check(s, j + 1, num):
                    return True
            return i == len(s)

        return check(s)