# 1318. Minimum Flips to Make a OR b Equal to c ###### tags: `Python`,`Leetcode` https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/ ```python= class Solution: def minFlips(self, a: int, b: int, c: int) -> int: ans = 0 # 用來記翻轉次數 while not a == b == c == 0: # 如果 a=b=c 轉都不用轉,直接 return 0 a, A = divmod(a,2) # divmod() -> a/2 輸出(餘數, 商數) 的 tuple。因為二進位整數部分,把十進位轉成二進位一直分解至商數為0。讀餘數從下讀到上,即是二進位的整數部分數字 b, B = divmod(b,2) c, C = divmod(c,2) if A == B == 1 and C == 0 : ans+= 2 # 如果 A,B 都是 1,但 C 是 0,要 A,B 布林運算 = 0 要翻轉兩次 elif A == B == 0 and C == 1 : ans+= 1 # 如果 A,B 都是 0,但 C 是 1,要 A,B 布林運算 = 0 要翻轉一次 elif A != B and C == 0 : ans+= 1 # 如果 A 或 B 一個 1 一個 0 ,但 C 是 0,要 A,B 布林運算 = 0 要翻轉ㄧ次 return ans ```