public class Solution { public int addDigits(int num) { //return (num - 1) % 9 + 1; int res = num % 9; return (res != 0 || num == 0) ? res : 9; } }