Given an integer N. What is the smallest integer greater than N that only has 0 or 1 as its digits? : <p>I have an integer N. I have to find the smallest integer greater than N that doesn't contain any digit other than 0 or 1. For example: If <code>N = 12</code> then the answer is <code>100</code>. 
I have coded a brute force approach in C++. </p>

<pre><code>int main() {
    long long n;
    cin &gt;&gt; n;

    for (long long i = n + 1; ; i++) {
        long long temp = i;
        bool ok = true;
        while (temp != 0) {
            if ( (temp % 10) != 0 &amp;&amp; (temp % 10) != 1) {
                ok = false;
                break;
            }
            temp /= 10;
        }
        if (ok == true) {
            cout &lt;&lt; i &lt;&lt; endl;
            break;
        }
    }
}
</code></pre>

<p>The problem is, my approach is too slow. I believe there is a very efficient approach to solve this.  How can I solve this problem efficiently?</p>
