leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0258.cpp (260B)


      1 class Solution {
      2   public:
      3     int addDigits(int num) {
      4         while (num >= 10) {
      5             int sum = 0;
      6             do {
      7                 sum += num % 10;
      8             } while ((num /= 10) > 0);
      9             num = sum;
     10         }
     11         return num;
     12     }
     13 };