Skip to content
Open
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
@@ -1,28 +1,33 @@
# [1317.Convert Integer to the Sum of Two No-Zero Integers][title]

> [!WARNING|style:flat]
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)

## Description
**No-Zero integer** is a positive integer that **does not contain any** `0` in its decimal representation.

Given an integer `n`, return a list of two integers `[a, b]` where:

- `a` and `b` are **No-Zero integers**.
- `a + b = n`

The test cases are generated so that there is at least one valid solution. If there are many valid solutions, you can return any of them.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
Input: n = 2
Output: [1,1]
Explanation: Let a = 1 and b = 1.
Both a and b are no-zero integers, and a + b = 2 = n.
```

## 题意
> ...
**Example 2:**

## 题解

### 思路1
> ...
Convert Integer to the Sum of Two No-Zero Integers
```go
```

Input: n = 11
Output: [2,9]
Explanation: Let a = 2 and b = 9.
Both a and b are no-zero integers, and a + b = 11 = n.
Note that there are other valid answers as [8, 3] that can be accepted.
```

## 结语

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
package Solution

func Solution(x bool) bool {
return x
func ok(n int) bool {
for n > 0 {
mod := n % 10
if mod == 0 {
return false
}
n /= 10
}
return true
}

func Solution(n int) []int {
nums := make(map[int]struct{})
for i := 1; i <= 10000; i++ {
if ok(i) {
nums[i] = struct{}{}
}
}
var diff int
for k := range nums {
diff = n - k
if _, ok := nums[diff]; ok {
return []int{k, diff}
}
}
return []int{}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
expect bool
inputs int
expect []int
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", 2, []int{1, 1}},
}

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

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

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