1 class Solution { 2 public: 3 int addDigits(int num) { 4 if(num == 0 ) return num; 5 else return num % 9 == 0 ? 9 : num % 9; 6 } 7 };
就是数位根!
1 class Solution { 2 public: 3 int addDigits(int num) { 4 if(num == 0 ) return num; 5 else return num % 9 == 0 ? 9 : num % 9; 6 } 7 };
就是数位根!