2 ways to solve in Javascript
Code\n\n/**\n * @param {number} num\n * @return {number}\n */\nvar findComplement = function(num) {\n    // -- Solution 1:\n    // let s = num.toString(2);\n   
# Code\n```\n/**\n * @param {number} num\n * @return {number}\n */\nvar findComplement = function(num) {\n    // -- Solution 1:\n    // let s = num.toString(2);\n    // let s1 = \'\';\n    // for(let i = 0; i < s.length; i++)\n    // {\n    //     s1 += (s[i] == \'0\') ? \'1\' : \'0\';\n    // }\n    // return parseInt(s1, 2);\n\n\n    // -- Solution 2:\n    let binaryString = num.toString(2);\n    let complementChars = [];\n\n    for (let i = 0; i < binaryString.length; i++) {\n        complementChars.push((binaryString[i] === \'0\') ? \'1\' : \'0\');\n    }\n\n    let complementBinary = complementChars.join(\'\');\n    return parseInt(complementBinary, 2);\n};\n```
['JavaScript']