Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1221 from sxsmg/1849-Splitting-a-Strin…
Browse files Browse the repository at this point in the history
…g-Into-Descending-Consecutive-Values.py

Create 1849-Splitting-a-String-Into-Descending-Consecutive-Values.py
  • Loading branch information
Ahmad-A0 authored Oct 8, 2022
2 parents 07db9af + 14a68bc commit 78d8e2a
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution:
def splitString(self, s: str) -> bool:

def dfs(index, prev):
if index == len(s):
return True

for j in range(index, len(s)):
val = int(s[index:j+1])
if val + 1 == prev and dfs(j+1, val):
return True
return False

for i in range(len(s) - 1):
val = int(s[:i + 1])
if dfs(i+1, val): return True

return False

0 comments on commit 78d8e2a

Please sign in to comment.