😎Java | 💥4 Step Logic | 🚀 Beginner friendly Solution 💯 
Intuition:1.Start with the number n and convert it to base -2.2.Find the last digit by doing n % (-2). This gives you either 0 or 1.
If the result is negative,
# Intuition:
1.Start with the number n and convert it to base -2.

2.Find the last digit by doing n % (-2). This gives you either 0 or 1.
If the result is negative, we change it to positive by adding 2 and decrease n by 1 to balance things.

            int lastDig = n % (-2);
            if (lastDig < 0) {
                lastDig += 2;
                n--;
            }
3.Add the last digit to the result string.

            binary = lastDig + binary;
4.Divide n by -2 and repeat until n becomes 0.

            n /= (-2);
5.Return the result when done.

        return binary;
# Explanation:
We are doing the same process as base 2, but instead of dividing by 2, we divide by -2.
If the remainder is negative, we adjust it to be positive, then fix n by subtracting 1.
Keep doing this until n becomes zero, and we get the correct binary representation in base -2.
# Complexity:
**Time:** O(log N) because we divide by -2 repeatedly.
**Space:** O(log N) because we build the result string as we go.
This method is similar to how you'd convert numbers to regular binary, but with adjustments for the negative base.

# Code
```java []
class Solution {
    public String baseNeg2(int n) {
        String binary = "";
        if (n == 0) return "0";
        while (n != 0) {
            int lastDig = n % (-2);
            if (lastDig < 0) {
                lastDig += 2;
                n--;
            }
            binary = lastDig + binary;
            n /= (-2);
        }
        return binary;
    }
}
```
['Java']