Leetcode 476. Number Complement

来源:互联网 发布:ntp服务器修改端口 编辑:程序博客网 时间:2024/06/11 01:34
public class Solution {    public int findComplement(int num) {        int res = 0;        int carry = 1;        while (num > 0) {            int temp = (num%2 == 0) ? 1 : 0;            res += temp*carry;            carry *= 2;            num /= 2;        }        return res;    }}

0 0
原创粉丝点击