My Java DP solution


  • 0
    S

    Though it is not fastest, it is very easy to understand.

    public class Solution {
        public int newInteger(int n) {
            if (n < 9) {
                return n;
            }
            if (n == 9) {
                return 10;
            }
            return newInteger(n / 9) * newInteger(9) + newInteger(n % 9);
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.