c# solution without using inbuild functions


  • 0
    D
    public class Solution {
        public string ConvertToBase7(int num) {
            int temp=num;
            if(temp==0)
            return "0";
            string s = "";
            num = num>0? num:num*(-1);
            while(num>0)
            {
                s = (num%7 == 0 ? 0:num%7)+s;
                num=num/7;
            }
            if(temp < 0)
            return "-"+s;
            else return s;
        }
    }
    

Log in to reply
 

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