my java solution w/o string helper


  • 2
    public class Solution {
        public String convertToBase7(int num) {
            int base = 1, result = 0;
            while (num != 0) {
                result += base * (num % 7);
                num /= 7;
                base *= 10;
            }
            return String.valueOf(result);
        }
    }
    

Log in to reply
 

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