Create 258. Add Digits.md

This commit is contained in:
唐树森 2018-09-29 23:49:30 +08:00 committed by GitHub
parent 4706c076e2
commit ee45883d22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

21
258. Add Digits.md Normal file
View File

@ -0,0 +1,21 @@
# [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;
}
};
```