# 1318. Minimum Flips to Make a OR b Equal to c

• Time: $O(30) = O(1)$
• Space: $O(1)$
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 class Solution { public: int minFlips(int a, int b, int c) { constexpr int kMaxBit = 30; int ans = 0; for (int i = 0; i < kMaxBit; ++i) if ((c >> i & 1) == 1) ans += (a >> i & 1) == 0 && (b >> i & 1) == 0; else // (c >> i & 1) == 0 ans += ((a >> i & 1) == 1) + ((b >> i & 1) == 1); return ans; } }; 
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 class Solution { public int minFlips(int a, int b, int c) { final int kMaxBit = 30; int ans = 0; for (int i = 0; i < kMaxBit; ++i) if ((c >> i & 1) == 1) ans += ((a >> i & 1) == 0 && (b >> i & 1) == 0) ? 1 : 0; else // (c >> i & 1) == 0 ans += ((a >> i & 1) == 1 ? 1 : 0) + ((b >> i & 1) == 1 ? 1 : 0); return ans; } } 
  1 2 3 4 5 6 7 8 9 10 11 12 class Solution: def minFlips(self, a: int, b: int, c: int) -> int: kMaxBit = 30 ans = 0 for i in range(kMaxBit): if (c >> i & 1) == 1: ans += (a >> i & 1) == 0 and (b >> i & 1) == 0 else: # (c >> i & 1) == 0 ans += ((a >> i & 1) == 1) + ((b >> i & 1) == 1) return ans