easy c++ solution


  • 0
    Y

    class Solution {
    public:
    int findComplement(int num) {
    vector<int> binary;
    while (num != 0){
    binary.push_back(num%2);
    num = num/2;
    }
    int result = 0;
    for (int i = 0; i < binary.size(); i ++){
    if (binary[i] == 0)
    result = result + pow(2, i);
    }
    return result;
    }
    };


Log in to reply
 

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