Skip to content

258_AddDigits

a920604a edited this page Apr 14, 2023 · 1 revision

title: 258. Add Digits tags: - Math categories: leetcode comments: false

solution

class Solution {
public:
    int addDigits(int num) {
        int n = num ;
        while(n>=10){
            int sum = 0;
            while(n){
                sum+=(n%10);
                n/=10;
            }
            n = sum;
        }
        return n;
        
    }
};
Clone this wiki locally