diff --git a/interview_prep/coding/dsa/extract_nums.py b/interview_prep/coding/dsa/extract_nums.py index 2d116df..48dc7ea 100644 --- a/interview_prep/coding/dsa/extract_nums.py +++ b/interview_prep/coding/dsa/extract_nums.py @@ -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 @@ -26,4 +26,4 @@ def extract_nums(ip): ip = "avdcfsd3212ad123ad" op = ["3212", "123"] - assert Solution.extract_nums(ip) == op \ No newline at end of file + assert Solution.extract_nums(ip) == op