-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1040 from 0xff-dev/2729
Add solution and test-cases for problem 2729
- Loading branch information
Showing
3 changed files
with
62 additions
and
8 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
leetcode/2701-2800/2729.Check-if-The-Number-is-Fascinating/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
24 changes: 22 additions & 2 deletions
24
leetcode/2701-2800/2729.Check-if-The-Number-is-Fascinating/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters