JAVA simple solution...


  • 0
    D
    public class Solution {
        public int countNumbersWithUniqueDigits(int n) {
            int a = 1, b = 1, limit = Math.min(n, 10), sum=0;
            for (int i=2; i<=limit; i++) {
                a*=10;
                b*=(10-i+1);
                sum+=9 * (a-b);
            }
            return (int)(Math.pow(10, limit) - sum);
        }
    }
    

Log in to reply
 

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