Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 7 additions & 2 deletions leetcode/0190.Reverse-Bits/190. Reverse Bits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package leetcode

import (
"fmt"
"strconv"
"testing"
)

Expand All @@ -23,7 +24,6 @@ type ans190 struct {
}

func Test_Problem190(t *testing.T) {

qs := []question190{

{
Expand All @@ -41,7 +41,12 @@ func Test_Problem190(t *testing.T) {

for _, q := range qs {
_, p := q.ans190, q.para190
fmt.Printf("【input】:%v 【output】:%v\n", p, reverseBits(p.one))
input := strconv.FormatUint(uint64(p.one), 2) // 32位无符号整数转换为二进制字符串
input = fmt.Sprintf("%0*v", 32, input) // 格式化输出32位,保留前置0
output := reverseBits(p.one)
outputBin := strconv.FormatUint(uint64(output), 2) // 32位无符号整数转换为二进制字符串
outputBin = fmt.Sprintf("%0*v", 32, outputBin) // 格式化输出32位,保留前置0
fmt.Printf("【input】:%v 【output】:%v (%v)\n", input, output, outputBin)
}
fmt.Printf("\n\n\n")
}
5 changes: 4 additions & 1 deletion leetcode/0191.Number-of-1-Bits/191. Number of 1 Bits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package leetcode

import (
"fmt"
"strconv"
"testing"
)

Expand Down Expand Up @@ -40,7 +41,9 @@ func Test_Problem191(t *testing.T) {

for _, q := range qs {
_, p := q.ans191, q.para191
fmt.Printf("【input】:%v 【output】:%v\n", p, hammingWeight(p.one))
input := strconv.FormatUint(uint64(p.one), 2) // 32位无符号整数转换为二进制字符串
input = fmt.Sprintf("%0*v", 32, input) // 格式化输出32位,保留前置0
fmt.Printf("【input】:%v 【output】:%v\n", input, hammingWeight(p.one))
}
fmt.Printf("\n\n\n")
}