题解 | #牛群编号转换#

牛群编号转换

https://www.nowcoder.com/practice/6a5ed8ca0a454e3a93f5e2b2e7502651

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param num int整型 
     * @return string字符串
     */
    public String convert_to_base6 (int num) {
        // write code here
        int x=num;
        if(num<0) x=-num;
        if(x==0) return "0";
        String ans="";
        while(x!=0){
            ans=x%6+ans;
            x=x/6;
        }
        return num>0?ans:"-"+ans;
    }
}

全部评论

相关推荐

07-02 13:52
武汉大学 golang
骗你的不露头也秒
牛客87776816...:😃查看图片
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 18:05
点赞 评论 收藏
分享
06-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务