1009. Complement of Base 10 Integer


class Solution {
    public int bitwiseComplement(int N) {
    String x = Integer.toBinaryString(N);
        StringBuilder out = new StringBuilder();
        for (int i = 0; i <span id="mce_SELREST_start" style="overflow:hidden;line-height:0;">&#65279;</span>&lt; x.length(); i++){
            if(x.charAt(i) == &#039;0&#039;)
            else out.append(&quot;0&quot;);
        return Integer.parseInt(out.toString(), 2);

Better Solution

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s