Skip to content

Commit

Permalink
Update extract_nums.py
Browse files Browse the repository at this point in the history
  • Loading branch information
akashsonowal authored Dec 5, 2023
1 parent 9505cc9 commit 6c5df90
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions interview_prep/coding/dsa/extract_nums.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ def extract_nums(ip):
res = []

while i < len(ip):
if ip[i].isdigit():
l = r = i
while l >= 0 and ip[l].isdigit():
l -= 1
while r < len(ip) and ip[r].isdigit():
r += 1
res.append(ip[l + 1: r])
i = r
else:
i += 1
if ip[i].isdigit():
l = r = i
while l >= 0 and ip[l].isdigit():
l -= 1
while r < len(ip) and ip[r].isdigit():
r += 1
res.append(ip[l + 1: r])
i = r
else:
i += 1

return res

Expand All @@ -26,4 +26,4 @@ def extract_nums(ip):
ip = "avdcfsd3212ad123ad"
op = ["3212", "123"]

assert Solution.extract_nums(ip) == op
assert Solution.extract_nums(ip) == op

0 comments on commit 6c5df90

Please sign in to comment.