Skip to content
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
@@ -1,28 +1,32 @@
# [1780.Check if Number is a Sum of Powers of Three][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
Given an integer `n`, return `true` if it is possible to represent `n` as the sum of distinct powers of three. Otherwise, return `false`.

An integer `y` is a power of three if there exists an integer `x` such that `y == 3^x`.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
Input: n = 12
Output: true
Explanation: 12 = 31 + 32
```

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

## 题解

### 思路1
> ...
Check if Number is a Sum of Powers of Three
```go
```
Input: n = 91
Output: true
Explanation: 91 = 30 + 32 + 34
```

**Example 3:**

```
Input: n = 21
Output: false
```

## 结语

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

func Solution(x bool) bool {
return x
func Solution(n int) bool {
arr := make([]int, 15)
arr[0] = 1
for i := 1; i < 15; i++ {
arr[i] = arr[i-1] * 3
}
var ok func(int, int) bool
ok = func(index, cur int) bool {
if cur == 0 {
return true
}
if index == 15 {
return false
}

return ok(index+1, cur-arr[index]) || ok(index+1, cur)
}
return ok(0, n)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ 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", 12, true},
{"TestCase2", 91, true},
{"TestCase3", 21, false},
}

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

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

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