随笔分类 -  Book: Coding Interview

[LeetCode] 231. Power of Two
摘要:Using O(1) time to check whether an integer n is a power of 2. Example For n=4, return true; For n=5, return false; 思路: 知识点: n & (n - 1) 使得从右边数最后一个1变为 阅读全文

posted @ 2016-07-19 11:43 codingEskimo 阅读(129) 评论(0) 推荐(0)

Update Bits
摘要:参考http://www.hawstein.com/posts/5.1.html 方案1:先将N中第0位到第i位保存下来(左闭右开:[0, i)),记作ret, 然后将N中第0位到第j位全清0([0, j]),通过向右移动j+1位然后再向左移动j+1位得到。 最后用上面清0后的值或上(m«i)再或上 阅读全文

posted @ 2016-07-19 11:40 codingEskimo 阅读(141) 评论(0) 推荐(0)

Count 1 in Binary
摘要:方法二: num & (num -1) 一直就把最后一个非0位变成1, 一直变到所有的都是0, 那么process了几次, 就是有几位1 阅读全文

posted @ 2016-07-19 11:11 codingEskimo 阅读(111) 评论(0) 推荐(0)

[LeetCode] 206. Reverse Linked List
摘要:/** * Definition for ListNode. * public class ListNode { * int val; * ListNode next; * ListNode(int val) { * this.val = val; * this.next = null; * } * 阅读全文

posted @ 2015-12-01 09:54 codingEskimo 阅读(108) 评论(0) 推荐(0)

Singleton
摘要:class Solution { /** * @return: The same instance of this class every time */ //http://www.cnblogs.com/EdwardLiu/p/4443230.html ... 阅读全文

posted @ 2015-12-01 09:35 codingEskimo 阅读(147) 评论(0) 推荐(0)

[LintCode] Count 1 in Binary
摘要:Count how many 1 in binary representation of a 32-bit integer. Example Given 32, return 1 Given 5, return 2 Given 1023, return 9 Count how many 1 in b 阅读全文

posted @ 2015-11-13 12:41 codingEskimo 阅读(134) 评论(0) 推荐(0)

String Replacement
摘要:public class Solution { /** * @param string: An array of Char * @param length: The true length of the string * @return: The true length... 阅读全文

posted @ 2015-11-13 11:24 codingEskimo 阅读(253) 评论(0) 推荐(0)

Fibonacci
摘要:1) Non-recursive: class Solution { /** * @param n: an integer * @return an integer f(n) */ public int fibonacci(int n) { // ... 阅读全文

posted @ 2015-11-13 10:49 codingEskimo 阅读(101) 评论(0) 推荐(0)

导航