P18886 [GeeksforGeeks] Sum of numbers in string 1587115621
普及-
题目描述

Given a string str containing alphanumeric characters. The task is to calculate the sum of all the numbers present in the string.
Example 1:
Input:
str = 1abc23
Output: 24
Explanation: 1 and 23 are numbers in the
string which is added to get the sum as
24.
Example 2:
Input:
str = geeks4geeks
Output: 4
Explanation: 4 is the only number, so the
sum is 4.
Your Task:
The task is to complete the function findSum() which finds and returns the sum of numbers in the string.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1 <= length of the string <= 10^{5}
Sum of Numbers <= 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
str = 1abc23
样例输出
24