less than 1 minute read

Given a positive integer num, return the sum of its digits.

Bonus: Can you do it without using strings?

Constraints

  • 0 ≤ num < 2 ** 31

https://binarysearch.com/problems/Sum-of-the-Digits

Examples

Example 1

Input

  • num = 123

Output

  • answer = 6

Explanation

Since 6 = 1 + 2 + 3

Example 2

Input

  • num = 50

Output

  • answer = 5

Explanation

Since 5 = 5 + 0

Solution

Leave a comment