Leetcode 357 Solution

This article provides solution to leetcode question 357 (count-numbers-with-unique-digits)

https://leetcode.com/problems/count-numbers-with-unique-digits

Solution

class Solution { public: int countNumbersWithUniqueDigits(int n) { int total = 1; int curr = 1;
for (int i = 0; i < n; i++) { if (i == 0) curr = 9; else curr *= 10 - i; total += curr; }
return total; } };