프로그래밍/LeetCode
[LeetCode][Python3] 357. Count Numbers with Unique Digits
snoopybox
2019. 8. 29. 00:05
Problem :
https://leetcode.com/problems/count-numbers-with-unique-digits/
My Solution :
class Solution:
def countNumbersWithUniqueDigits(self, n):
ans = 1
for x in range(1, n+1):
part = 9
while x > 1:
part *= (11-x)
x -= 1
ans += part
return ans
Comment :
단순 경우의 수 문제이다. 각 자리수 별로 아래와 같이 구해서 다 더하면 된다.
1 n==0
9 n==1
9 * 9 n==2
9 * 9 * 8 n==3
9 * 9 * 8 * 7 n==4