String Number Summation
Problem Given a string containing digits interspersed with other characters, extract every maximal run of consecutive digits as an integer and return the sum of those integers.
Input / Output
- Input: a string
s. - Output: the integer sum of all numbers embedded in
s.
Constraints
- 0 ≤ |s| ≤ 10^5.
- A "number" is a maximal run of consecutive digit characters; non-digits are separators.
- An empty string, or one with no digits, sums to 0.
Example
"a12b3c45"→ 60 (12 + 3 + 45)."abc"→ 0;"007"→ 7.
added …