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;
}
}
Leetcode 476. Number Complement
最新推荐文章于 2021-06-08 11:11:10 发布