Numbers At N Given Digit Set | Leetcode November Challenge Day 21 | Leetcode 902

preview_player
Показать описание
Here is the solution to "Numbers At N Given Digit Set" leetcode question. Hope you have a great time going through it.

Quick Links
1) 0:00 Explaining the problem out loud
2) 1:02 Algorithm walkthrough
3) 9:10 Coding it up

Solution

PS : Please increase the speed to 1.25X
Рекомендации по теме
Комментарии
Автор

Best explanation across all the videos there on youtube for this question

rajatsethi
Автор

Brute force solution

class Solution {
public:
bool num[10];

int helper(long long n, long long number){
if(n<number){
return 0;
}
int res=(number<=n);
for(int i=1;i<=9;i++){
if(num[i]==true){
int temp=helper(n, number*10+i);
if(temp==0){
break;
}
res+=temp;
}
}
return res;
}

int digits, int n) {
memset(num, sizeof(num), false);
for(auto c: digits){
num[c[0]-'0']=true;
}
return helper(n, 0)-1;
}
};

The_Promised_Neverland...
visit shbcf.ru