摘要:
做到第三个power of XXX的题的时候觉得不对了……再蠢也不会出3个一样,仔细看了下别人的方法。。 2 10 4 100 8 1000 power of 2.... n & (n 1) == 0 4的话也差不多,首先得都是2的power,然后4是隔1位有1个。。所以2 4 6 8这种位是不能有 阅读全文
posted @ 2016-10-21 11:59
哇呀呀..生气啦~
阅读(81)
评论(0)
推荐(0)
摘要:
Tried to get this done recursively in the first place. But then I realized I could not do that since the target coulde be larger than Integer.MAX_VALU 阅读全文
posted @ 2016-10-21 09:28
哇呀呀..生气啦~
阅读(128)
评论(0)
推荐(0)
摘要:
楞做。 java public class Solution { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { if(l1 == null || l2 == null) return l1 == null ? l2:l1; Lis 阅读全文
posted @ 2016-10-21 08:45
哇呀呀..生气啦~
阅读(73)
评论(0)
推荐(0)
摘要:
一开始没发现是BST,以为是binary tree...草。。 二刷?其实不知道是几刷。 用的递归,就3种情况,左边,右边,当前。 Time: iteratively O(n) recursively O(n) as well Space: Iteratively better than recur 阅读全文
posted @ 2016-10-21 08:38
哇呀呀..生气啦~
阅读(75)
评论(0)
推荐(0)
摘要:
判断负数容易忘。 java public class Solution { public boolean isUgly(int num) { if(num == 1) return true; if(num 阅读全文
posted @ 2016-10-21 07:58
哇呀呀..生气啦~
阅读(92)
评论(0)
推荐(0)
摘要:
这个题最难的地方在于如何拼写fibonacci这个名字。 java public class Solution { public int climbStairs(int n) { // dp[n] = dp[n 1] + dp[n 2]; if(n 阅读全文
posted @ 2016-10-21 07:52
哇呀呀..生气啦~
阅读(83)
评论(0)
推荐(0)
摘要:
一位一位算。 阅读全文
posted @ 2016-10-21 07:46
哇呀呀..生气啦~
阅读(66)
评论(0)
推荐(0)
摘要:
比较熟悉的股票问题,动态规划典型。 这是第一道,比较简单。 用的思路是局部变量+全局变量。 Java public class Solution { public int maxProfit(int[] prices) { if(prices.length 阅读全文
posted @ 2016-10-21 07:39
哇呀呀..生气啦~
阅读(160)
评论(0)
推荐(0)
摘要:
as same as power of Three java public class Solution { public boolean isPowerOfTwo(int n) { if(n 阅读全文
posted @ 2016-10-21 06:58
哇呀呀..生气啦~
阅读(63)
评论(0)
推荐(0)
摘要:
二刷卡,不让用LOOP之类的,那就是数学方式,那就说明我肯定不会。 log3(n)= log10(n) / log10(3).. java public class Solution { public boolean isPowerOfThree(int n) { if(n 阅读全文
posted @ 2016-10-21 06:54
哇呀呀..生气啦~
阅读(101)
评论(0)
推荐(0)