-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Abhinav1101/main
Added count numbers with unique digits
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Leetcode Solution/Dynamic Programming/Medium/357. Count Numbers with Unique Digits.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Solution { | ||
public: | ||
int cal(int n){ | ||
int val =9,dif=9; | ||
while(n>1){ | ||
dif*=val; | ||
val--; | ||
n--; | ||
} | ||
return dif; | ||
} | ||
int countNumbersWithUniqueDigits(int n) { | ||
if(n==0) | ||
return 1; | ||
int ans = 10; | ||
for(int i=2;i<=n;i++) | ||
ans+=cal(i); | ||
return ans; | ||
} | ||
}; |