public static String DecimaltoBinary(int num){ char[] ch = Integer.toBinaryString(num).toCharArray(); String res = "";                 if(ch.length == 1 && ch[0] == '0'){ return "0"; } //从左到右记录幂的位置 int temp = ch.length-1; String s = ""; for (int i = 0; i < ch.length; i++) { if (ch[i] == '1') { if(temp > 2) { s = DecimaltoBinary(temp); }else{ s = temp+""; } if(res == "") { res += "2(" + s + ")"; } else { res += "+" + "2(" + s + ")"; } } temp--; } return res; } 就一个递归调用,没有多判断负数,上面有大神已经判断了!不过没想过复杂度的问题,能力不够
点赞 1

相关推荐

09-02 11:14
已编辑
四川大学 Java
吴offer选手:这种面试是最烦的,学不到东西,然后还被挂的莫名其妙。之前看到一种说法是面试官如果不想要你了,就会问一些很简单的问题,防止你举报他
点赞 评论 收藏
分享
今年hc多吗。。双非真无力了
投递比亚迪等公司10个岗位
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务