2864. 最大二进制奇数

最大二进制奇数

解法一: 模拟

go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
func maximumOddBinaryNumber(s string) string {
one := countOne(s)
return strings.Repeat("1", one-1) + strings.Repeat("0", len(s)-one) + "1"
}

func countOne(str string) int {
count := 0
for _, ch := range str {
if ch == '1' {
count++
}
}
return count
}
作者

wuhunyu

发布于

2024-03-13

更新于

2024-03-13

许可协议

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×