七进制数 (Base 7)

 

思路:

// @Title: 七进制数 (Base 7)
// @Author: qisiii
// @Date: 2022-03-07 10:18:02
// @Runtime: 1 ms
// @Memory: 39 MB
// @comment: 
// @flag: 
class Solution {
    public String convertToBase7(int num) {
        StringBuilder str=new StringBuilder();
        List<Integer> result=new ArrayList();
        while(Math.abs(num)>=7){
            result.add(0,Math.abs(num%7));
            num=num/7;
        }
        str.append(num);
        for(int i:result){
            str.append(i);
        }
        return str.toString();
    }
}
Licensed under CC BY-NC-SA 4.0
最后更新于 2024-10-18