LeetCode/solutions/258. Add Digits.md

22 lines
461 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# [258. Add Digits](https://leetcode.com/problems/add-digits/description/)
# 思路
没什么好说的按照题目的意思用两个while循环即可。
# C++
```
class Solution {
public:
int addDigits(int num) {
int res = 0;
while(num >= 10){
while(num > 0){
res += (num % 10);
num /= 10;
}
num = res;
res = 0;
}
return num;
}
};
```