Skip to content

Commit 1d7ab48

Browse files
refactor 357
1 parent ab37f41 commit 1d7ab48

File tree

1 file changed

+0
-17
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+0
-17
lines changed

src/main/java/com/fishercoder/solutions/_357.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 357. Count Numbers with Unique Digits
5-
* Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.
6-
7-
Example:
8-
Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excluding [11,22,33,44,55,66,77,88,99])
9-
10-
Hint:
11-
A direct way is to use the backtracking approach.
12-
Backtracking should contains three states which are
13-
(the current number, number of steps to get that number and a bitmask which
14-
represent which number is marked as visited so far in the current number).
15-
Start with state (0,0,0) and count all valid number till we reach number of steps equals to 10n.
16-
This problem can also be solved using a dynamic programming approach and some knowledge of combinatorics.
17-
Let f(k) = count of numbers with unique digits with length equals k.
18-
f(1) = 10, ..., f(k) = 9 * 9 * 8 * ... (9 - k + 2) [The first factor is 9 because a number cannot start with 0].
19-
*/
203
public class _357 {
214

225
public static class Solution1 {

0 commit comments

Comments
 (0)