Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add solution and test-cases for problem 2729 #1040

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# [2729.Check if The Number is Fascinating][title]

## Description
You are given an integer `n` that consists of exactly `3` digits.

We call the number `n` **fascinating** if, after the following modification, the resulting number contains all the digits from `1` to `9` **exactly** once and does not contain any `0`'s:

- **Concatenate** `n` with the numbers `2 * n` and `3 * n`.

Return `true` if `n` is fascinating, or `false` otherwise.

**Concatenating** two numbers means joining them together. For example, the concatenation of `121` and `371` is `121371`.

**Example 1:**

```
Input: n = 192
Output: true
Explanation: We concatenate the numbers n = 192 and 2 * n = 384 and 3 * n = 576. The resulting number is 192384576. This number contains all the digits from 1 to 9 exactly once.
```

**Example 2:**

```
Input: n = 100
Output: false
Explanation: We concatenate the numbers n = 100 and 2 * n = 200 and 3 * n = 300. The resulting number is 100200300. This number does not satisfy any of the conditions.
```

## 结语

如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解:[awesome-golang-algorithm][me]

[title]: https://leetcode.com/problems/check-if-the-number-is-fascinating
[me]: https://github.com/kylesliu/awesome-golang-algorithm
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
package Solution

func Solution(x bool) bool {
return x
func Solution(n int) bool {
checker := [10]int{}
var checkNum func(n int)
checkNum = func(n int) {
for n > 0 {
x := n % 10
checker[x]++
n /= 10
}
}
checkNum(n)
checkNum(n + n)
checkNum(n + n + n)
if checker[0] > 0 {
return false
}
for i := 1; i < 10; i++ {
if checker[i] != 1 {
return false
}
}
return true
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
inputs int
expect bool
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", 192, true},
{"TestCase2", 100, false},
}

// 开始测试
Expand All @@ -30,10 +29,10 @@ func TestSolution(t *testing.T) {
}
}

// 压力测试
// 压力测试
func BenchmarkSolution(b *testing.B) {
}

// 使用案列
// 使用案列
func ExampleSolution() {
}
Loading