[LeetCode][Python3] 357. Count Numbers with Unique Digits
2019. 8. 29. 00:05 |
프로그래밍/LeetCode
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
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 739. Daily Temperatures (0) | 2019.09.12 |
---|---|
[LeetCode][Python3] 401. Binary Watch (0) | 2019.09.05 |
[LeetCode][Python3] 692. Top K Frequent Words (0) | 2019.09.03 |
[LeetCode][Python3] 89. Gray Code (0) | 2019.09.03 |
[LeetCode][Python3] 996. Number of Squareful Arrays (0) | 2019.08.28 |
[LeetCode][Python3] 174. Dungeon Game (0) | 2019.08.28 |
[LeetCode][Python3] 77. Combinations (0) | 2019.08.25 |
[LeetCode][Python3] 39. Combination Sum (0) | 2019.08.23 |
최근에 달린 댓글 최근에 달린 댓글