Leetcode Problem 1318. Minimum Flips to Make a OR b Equal to c

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

Leetcode Solutions

Bit Manipulation

  1. Initialize answer to 0.
  2. Loop while a, b, or c is not 0: a. If (c & 1) is 0, add (a & 1) + (b & 1) to answer. b. If (c & 1) is 1, and both (a & 1) and (b & 1) are 0, increment answer by 1. c. Right shift a, b, and c by 1.
  3. Return answer.
UML Thumbnail

Count Set Bits Using Built-in Function

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...