Sum of Digits in Text
s is a text with letters, digits and symbols. Add up the value of every digit character in it (each digit counted on its own, so 45 adds 4 and 5). Return the total, or 0 if there are no digits.
Example 1
s "a1b22c"
returns 5
1 + 2 + 2 = 5.
Constraints
0 <= len(s) <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- Truncate SentenceBeginner
- Two String Lists Spell the Same WordBeginner
- Vowel and Consonant TallyBeginner
- Abbreviate Long WordsEasy
- Buddy StringsEasy
- Caesar CipherEasy
- Capitalize Sentence StartsEasy
- Compare Version NumbersEasy