🚀🔥 Beating 100% 🚀 | ⚡ Ultimate Bitwise Complement Solution in Java! 💯✅
🧠 Intuition
The goal is to find the bitwise complement of a given number n.The bitwise complement flips all bits:
0 ➝ 1 ✅
1 ➝ 0 ❌
Instead of flipping each bit d
🧠 Intuition
The goal is to find the bitwise complement of a given number n.

The bitwise complement flips all bits:
0 ➝ 1 ✅
1 ➝ 0 ❌
Instead of flipping each bit directly, your approach reconstructs the complement by summing the powers of 2 corresponding to 0 bits. 🛠️

💡 Approach
1️⃣ Edge Cases:

If n == 0, return 1 (since 0 flips to 1). 🟢
If n == 1, return 0 (since 1 flips to 0). ❌
2️⃣ Convert n to Binary & Flip Bits:

Iterate through each bit of n from right to left. 🔄
If the current bit is 0, add the corresponding power of 2 to t. ⚡
Keep dividing n by 2 to process the next bit.
3️⃣ Return the Result 🎯

📊 Complexity Analysis
Time Complexity: 🕒 O(log n)
The loop runs while n > 1, which is approximately log₂(n) iterations. 📉
Space Complexity: 🏗 O(1)
Only a few variables (i, t, n) are used, making it constant space. ✅
🎯 Example Walkthrough
Input: n = 5
Binary Representation: 101 🔢
Complement Calculation:

1st bit: 1 → Skip
2nd bit: 0 → Add 2^1 = 2
3rd bit: 1 → Skip
Complement Result: 2 🎉

Output: 2 🚀

# Code
```java []
class Solution {
    public int bitwiseComplement(int n) {
        int i=0;
        double t=0;
        if(n==0)
        {
            return 1;
        }
        if(n==1)
        {
            return 0;
        }
        while(n>1)
        {
         
         if(n%2==0)
         {
            t=t+Math.pow(2,i);
         }
         i++;
         n/=2;
        }
        
      return (int)t;
    }
}
```
['Java']