halfrost / LeetCode-Go

✅ Solutions to LeetCode by Go, 100% test coverage, runtime beats 100% / LeetCode 题解
https://books.halfrost.com/leetcode
MIT License
32.76k stars 5.68k forks source link

Fixed display problems of uint32 type during go test #249

Closed Don2025 closed 2 years ago

Don2025 commented 2 years ago

修复了题目190和191运行go test时,uint32类型的显示问题。

for _, q := range qs {
      _, p := q.ans190, q.para190
      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)
}

这样在go test时就能与力扣官网的输入输出显示一致啦。望大佬采纳!

~/LeetCode-Go/leetcode/0190.Reverse-Bits$ go test
------------------------Leetcode Problem 190------------------------
【input】:00000010100101000001111010011100       【output】:964176192 (00111001011110000010100101000000)
【input】:11111111111111111111111111111101       【output】:3221225471 (10111111111111111111111111111111)

PASS
ok      github.com/halfrost/LeetCode-Go/leetcode/0190.Reverse-Bits      0.164s