摘要: 大家好 我是cxa 目前大二在读 这个博客主要记录一下平时刷的题和笔记~ 阅读全文
posted @ 2018-04-07 23:26 newmoonn 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数。 进阶:你可以不使用循环或者递归,且在 O(1) 时间复杂度内解决这个问题吗? 题解: 网上还有一种更劲的写法 假设输入的数字是一个5位数字num,则num的各位分别为a、b、c、d、e。 有如下关系:num = a * 1000 阅读全文
posted @ 2018-05-13 15:26 newmoonn 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 给定一个整数,写一个函数来判断它是否是 2 的幂次方。 阅读全文
posted @ 2018-05-08 19:49 newmoonn 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 给定一个整数 n,返回 n! 结果尾数中零的数量。 阅读全文
posted @ 2018-05-08 19:42 newmoonn 阅读(274) 评论(0) 推荐(0) 编辑
摘要: 给定一个大小为 n 的数组,找到其中的众数。众数是指在数组中出现次数大于 ⌊ n/2 ⌋ 的元素。 你可以假设数组是非空的,并且给定的数组总是存在众数。 题解: 阅读全文
posted @ 2018-05-08 19:39 newmoonn 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 假设你正在爬楼梯。需要 n 步你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数。 题解: 斐波那契 f[n]=f[n-1]+f[n-2] 注意复杂度 阅读全文
posted @ 2018-05-08 18:12 newmoonn 阅读(81) 评论(0) 推荐(0) 编辑
摘要: 输入一个数 判断它是不是回文数 题解: 因为如果是负数 那么肯定就不是 之后按第一位和最后一位比较 比较完移除来解决 题解: 阅读全文
posted @ 2018-05-08 18:08 newmoonn 阅读(91) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 int mySqrt(int x) { 4 long res = x; 5 while (res * res > x) { 6 res = (res + x / res) / 2; 7 } 8 return res; 9 ... 阅读全文
posted @ 2018-04-26 21:56 newmoonn 阅读(102) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 bool canWinNim(int n) { 4 if(n % 4 == 0) return false; 5 else return true; 6 } 7 }; 阅读全文
posted @ 2018-04-26 21:55 newmoonn 阅读(79) 评论(0) 推荐(0) 编辑
摘要: Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn’t ma 阅读全文
posted @ 2018-04-26 17:07 newmoonn 阅读(63) 评论(0) 推荐(0) 编辑