Easy JAVA Solution ||✅Beats 100% || Straight Forward
IntuitionApproach
Same as base 2 , Trick is how to handle the negative remainder
when remainder gets negative , we have to take to the range of 0 and 1 such tha
![image.png](https://assets.leetcode.com/users/images/60ed1442-7c74-45fa-9f3e-ffc08cc25161_1740676613.1113305.png)

# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
- Same as base 2 , Trick is how to handle the negative remainder 
- when remainder gets negative , we have to take to the range of 0 and 1 such that the loop continues till we get the number as 0.
- 
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
The time complexity of the conversion is O(log(|num|)), where |num| is the absolute value of the number being converted.
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
The space complexity is O(log(|num|)) due to the space required to store the result as a string.
# Code
```java []
class Solution {
    public String baseNeg2(int n) {
        if (n == 0) return "0";

        StringBuilder result = new StringBuilder();
        
        while (n != 0) {
            int remainder = n % -2;
            n /= -2;
            
            if (remainder < 0) {
                remainder += 2;
                n += 1;
            }
            
            result.append(remainder);
        }

        return result.reverse().toString();
    }
}
```
['Java']