Base 7
IntuitionThe basic idea is to repeatedly divide the number by 7 and collect the remainders. The remainders represent the digits of the number in base-7, but sin
# Intuition
The basic idea is to repeatedly divide the number by 7 and collect the remainders. The remainders represent the digits of the number in base-7, but since the process gives us digits in reverse order, we will need to reverse the result at the end.

# Approach
1.We handle the special case where num = 0 and return "0".
2.We convert the number to its absolute value, track the sign, and repeatedly divide by 7, collecting remainders as digits.
3.We append the digits to a StringBuilder and reverse the order.
4.If the number was negative, we add a "-" sign and return the final base-7 representation.
# Complexity
- Time complexity:
The time complexity is O(log7(N))

- Space complexity:
The space complexity is O(log7(N))

# Code
```java []
class Solution {
    public String convertToBase7(int num) {
        if(num==0)return "0";
        StringBuilder sb=new StringBuilder();
        int sign=(num>=0)?1:-1;
        num=Math.abs(num);
        while(num>0)
        {
            sb.append(num%7);
            num/=7;
        }
        if(sign==-1)sb.append('-');
        return sb.reverse().toString();
    }
}
```
['Java']