Bit manipulation WITHOUT Java API - LEARN BIT MANIPULATION!


  • 0
    J

    Work it out my hand and learn bits manipulation!

    public class Solution {
        public int findComplement(int num) {
            int size = 1;
            int same = num;
            while(same != 0) {
                size *= 2;
                same = same >> 1;
            }
            
            return ~num & (size-1);
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.