Java Solution


  • 0
    L
    public String convertToBase7(int num) {
            if(num==0) {
                return "0";
            }
            boolean signed=num<0;
            String s = "";
            while(num!=0) {
                s = Math.abs(num%7)+s;
                num = num/7;
            }
            if(signed) {
                s = "-" + s;
            }
            
            return s;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.