Complement of Base 10 Integer LeetCode solution in Java

1
class Solution {
2
public int bitwiseComplement(int n) {
3
String bin = Integer.toBinaryString(n);
4
String res = "";
5
for (char c : bin.toCharArray()) {
6
if (c == '1') res += "0";
7
else res += "1";
8
}
9
return Integer.parseInt(res, 2);
10
}
11
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0