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
41 changes: 29 additions & 12 deletions leetcode/3301-3400/3370.Smallest-Number-With-All-Set-Bits/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
# [3370.Smallest Number With All Set Bits][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
You are given a positive number `n`.

Return the **smallest** number `x` **greater than** or **equal to** `n`, such that the binary representation of `x` contains only set bits

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
Input: n = 5

Output: 7

Explanation:

The binary representation of 7 is "111".
```

**Example 2:**

```
Input: n = 10

Output: 15

## 题意
> ...
Explanation:

The binary representation of 15 is "1111".
```

## 题解
**Example 3:**

### 思路1
> ...
Smallest Number With All Set Bits
```go
```
Input: n = 3

Output: 3

Explanation:

The binary representation of 3 is "11".
```

## 结语

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

func Solution(x bool) bool {
return x
func Solution(n int) int {
base := 2
for i := 0; i < 10; i++ {
if base-1 >= n {
return base - 1
}
base *= 2
}
return 0
}
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
expect bool
inputs int
expect int
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", 5, 7},
{"TestCase2", 10, 15},
{"TestCase3", 3, 3},
}

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

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

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