摘要: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit 阅读全文
posted @ 2016-02-25 19:14 周洋 阅读(140) 评论(0) 推荐(0)
摘要: Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it without using any loop / recursion? //cmath里内置的有关 阅读全文
posted @ 2016-02-25 17:25 周洋 阅读(185) 评论(0) 推荐(0)
摘要: Given an integer, write a function to determine if it is a power of two. 题解:一次一次除2来做的话,效率低。所以使用位运算的方法(左移一位相当于原数乘2)列出在int范围内的所有2的倍数,然后和n异或如果等于0,那么n就是它( 阅读全文
posted @ 2016-02-25 15:47 周洋 阅读(274) 评论(0) 推荐(0)
摘要: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example,Given nums = [0, 1, 阅读全文
posted @ 2016-02-25 12:41 周洋 阅读(226) 评论(0) 推荐(0)
摘要: A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ num[i+1], find a peak element and return its inde 阅读全文
posted @ 2016-02-25 12:18 周洋 阅读(182) 评论(0) 推荐(0)
摘要: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or 阅读全文
posted @ 2016-02-25 10:58 周洋 阅读(172) 评论(0) 推荐(0)
摘要: Search for a Range Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexit 阅读全文
posted @ 2016-02-25 10:53 周洋 阅读(262) 评论(0) 推荐(0)