# 357. Count Numbers with Unique Digits

Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.

```
Example:
```

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])

Credits:Special thanks to @memoryless for adding this problem and creating all test cases.

## Solution <a href="#solution" id="solution"></a>

```java
public class Solution {
     public int countNumbersWithUniqueDigits(int n) {
                 if (n == 0) return 1;

        if (n == 1) return 10;

        int result = 0;
        for(int i = n; i >= 1; i --) {
            result += countNumbersWithUniqueDigitsHelper(i);
        }

        return result;

    }

    private int countNumbersWithUniqueDigitsHelper(int n) {
        if (n == 1) return 10;

        int result = 9;
        int current = 9;
        for(int i = n -1; i > 0; i --) {
            if (current == 0) {
                break;
            }

            result *= current;
            current --;
        }

        return result;
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://anand-aryan.gitbook.io/leetcode/357.-count-numbers-with-unique-digits.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
