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

class Solution {
public:
    int countNumbersWithUniqueDigits(int n) {
        if (n < 1) {
            return 1;
        }
        
        // one digit number
        int count = 9;
        int base = 9;
        int cur = 9;
        
        for (int i=1; i<n; ++i) {
            base *= cur;
            cur--;
            count += base;
        }
        
        // including the last one, equivalent to including 0
        return count + 1;
    }
};

 

相关文章:

  • 2022-12-23
  • 2021-05-13
  • 2021-10-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2021-09-19
猜你喜欢
  • 2022-12-23
  • 2022-01-09
  • 2021-08-12
  • 2021-04-04
  • 2021-10-27
  • 2021-06-11
相关资源
相似解决方案