Hyoseo Lee
Home About Projects Blog Thinking
leetcode

258. Add Digits

Topic Math
Area Algorithms
Summary
if it is single digit, return it. or, do the same process.

Problem

View on LeetCode →

Difficulty: Easy
Tags: Math, Simulation, Number Theory

Intuition

this one is easy. simple recursion question.

Approach

if it is single digit, return it. or, do the same process.

Solution

int addDigits(int num) {
    int tmp;
    if(num < 10){
        return num;
    }
    else{
        while(num > 0){
            tmp += num % 10;
            num = num/10;
        }
        return addDigits(tmp);
    }
}

Complexity

Thoughts

this one was way to easy.