MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / minBitFlips

Method minBitFlips

MinimumBitFlipsToConvertNumber.java:2–10  ·  view source on GitHub ↗
(int start, int goal)

Source from the content-addressed store, hash-verified

1class Solution {
2 public int minBitFlips(int start, int goal) {
3 int xor = start ^ goal;
4 int count=0;
5 while(xor>0){ //set bits O(32)
6 xor = xor & (xor-1);
7 count++;
8 }
9 return count;
10 }
11}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected