首页 > 其他 > 详细

357. Count Numbers with Unique Digits

时间:2020-04-08 01:20:09      阅读:55      评论:0      收藏:0      [点我收藏+]

Problem:

Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.

Example:

Input: 2
Output: 91 
Explanation: The answer should be the total numbers in the range of 0 ≤ x < 100, 
             excluding 11,22,33,44,55,66,77,88,99

思路

Solution (C++):

int countNumbersWithUniqueDigits(int n) {
    int unique_count = 0;
    for (int i = 0; i <= n; ++i) {
        unique_count += no_duplicate(i);
    }
    return unique_count;
}
int no_duplicate(int n) {
    if (n == 0)  return 1;
    int count = 9;
    for (int i = 1; i < n; ++i) {
        count *= (10-i);
    }
    return count;
}

性能

Runtime: 0 ms??Memory Usage: 6.1 MB

思路

Solution (C++):


性能

Runtime: ms??Memory Usage: MB

357. Count Numbers with Unique Digits

原文:https://www.cnblogs.com/dysjtu1995/p/12657221.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!