mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-06 01:15:57 +08:00
21 lines
264 B
Go
21 lines
264 B
Go
package leetcode
|
|
|
|
import "strconv"
|
|
|
|
func baseNeg2(N int) string {
|
|
if N == 0 {
|
|
return "0"
|
|
}
|
|
res := ""
|
|
for N != 0 {
|
|
remainder := N % (-2)
|
|
N = N / (-2)
|
|
if remainder < 0 {
|
|
remainder += 2
|
|
N++
|
|
}
|
|
res = strconv.Itoa(remainder) + res
|
|
}
|
|
return res
|
|
}
|