摘要: class Solution { public: bool isPowerOfThree(int n) { if(n<=0)return false; const int maxint=0x7fffffff; int k=log(maxint)/log(3); int answer=pow(3,k); ret... 阅读全文
posted @ 2018-05-13 15:32 newmoonn 阅读(118) 评论(0) 推荐(0)
摘要: 给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数。 进阶:你可以不使用循环或者递归,且在 O(1) 时间复杂度内解决这个问题吗? 题解: 网上还有一种更劲的写法 假设输入的数字是一个5位数字num,则num的各位分别为a、b、c、d、e。 有如下关系:num = a * 1000 阅读全文
posted @ 2018-05-13 15:26 newmoonn 阅读(189) 评论(0) 推荐(0)