LeetCode-476. Number Complement

时间:2017-01-20 12:46:11   收藏:0   阅读:355

Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.

public class Solution {
    public int findComplement(int num) {
        return ~num & ((Integer.highestOneBit(num)<<1) - 1);
    }
}

 

原文:http://www.cnblogs.com/wxisme/p/6322256.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!