Results of the first around operation against 32bit positive integer is less than 100, and let the maximum one be A. We can calculate final result for integers from 0 to A and store them into a static array m[0, ..., A]. For input x, we just need add all digits, let sum be s, and m[s] is final result. Both time and space complexity are O(1);
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.