lc-go/solutions/13/q1318/solution.go
2026-01-25 11:56:12 +09:00

28 lines
384 B
Go

package q1318
func minFlips(a int, b int, c int) int {
aorb := a | b
flips := 0
p := 1
for p <= aorb || p <= c {
switch {
case c|p == c && aorb|p != aorb:
flips++ // c has the bit
case c|p != c && aorb|p == aorb:
if a|p == a {
flips++ // a has the bit
}
if b|p == b {
flips++ // b has the bit
}
}
p <<= 1
}
return flips
}
var _ = minFlips