首页 > 其他 > 详细

[动态规划] leetcode 357 Count Numbers with Unique Digits

时间:2019-08-10 20:58:27      阅读:84      评论:0      收藏:0      [点我收藏+]

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

1 : 10

2: 10 + 9 x 9

3: 10 + 9 x 9 + 9 x 9 x 8

4: 10 + 9 x 9 + 9 x 9 x 8 x 7

……

class Solution {
public:
    int countNumbersWithUniqueDigits(int n) {
        if(n == 0) return 1;
        int llast = 1;
        int last = 10;
        for(int i = 2;i <= n;i++)
        {
            int result = last + (last - llast) * (10 - (i - 1));
            llast = last;
            last = result;
        }
        return last;
    }
};

 

[动态规划] leetcode 357 Count Numbers with Unique Digits

原文:https://www.cnblogs.com/fish1996/p/11332637.html

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