100 Beats Solution 👏| Math ⚡| Java 🎯
📌 Step-by-Step Breakdown:Handling Negative Numbers:
If num is negative, it is converted to a positive number for easier calculation, and a flag is set to track


# 📌 Step-by-Step Breakdown:
## **Handling Negative Numbers:**
- If num is negative, it is converted to a positive number for easier calculation, and a flag is set to track the sign.

## **Extracting Base-7 Digits:**
- The while(num > 0) loop repeatedly divides the number by 7 and collects the remainders (digits in Base-7).
Each digit is multiplied by powers of 10 to form the final number (n).

## **Restoring Sign:**
- If the flag indicates the original number was negative, the result is returned as a negative value.

## **Edge Case:**
- If the input num is 0, the function directly returns "0".
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: O(log7(𝑛))
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(log7(𝑛))
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
![a497d0b1-b512-40b1-9bca-4cbcaeb6befd_1709339631.914102.png](https://assets.leetcode.com/users/images/0ef59149-97e4-4a10-ab9c-c416915cc944_1742549411.562244.png)

# Code
```java []
class Solution {
    static int base(int num ){
        int flag=0 ,n=0,pov=1;
    
        if(num < 0){
            num*=-1;
            flag=1;
        }

        while(num > 0){
            int l= num % 7;
            n+=(l*(pov));
            pov*=10;
            num = num / 7;
        }

       return (flag == 1) ? -n : n;
    }
    public String convertToBase7(int num) {
        if(num == 0 ) return "0";
       return String.valueOf(base(num));
    }
}
```
['Math', 'Java']