1 class Solution { 2 public: 3 bool isPowerOfTwo(int n) { 4 int temp; 5 if(n==0) 6 return false; 7 if(n==1) 8...
分类:
其他好文 时间:
2015-07-07 00:44:43
阅读次数:
97
http://www.lintcode.com/en/problem/wood-cut/#
二分答案,贪心验证,具有单调性
class Solution {
public:
/**
*@param L: Given n pieces of wood with length L[i]
*@param k: An integer
*return...
分类:
其他好文 时间:
2015-07-06 23:30:25
阅读次数:
233
Gcc提供的内建函数__builtin_popcount(n),可以精确计算n表示成二进制时有多少个1。借助这个函数可以快速判断一个数是否是2的幂。1 bool isPowerOfTwo(int n)2 {3 return n>0 && __builtin_popcount(n)==1;4 ...
分类:
其他好文 时间:
2015-07-06 23:10:39
阅读次数:
115
Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
思路:对两个已排序的单链表合并。算法上比较简单,与归并排...
分类:
编程语言 时间:
2015-07-06 21:48:48
阅读次数:
166
在用vector排序的时候,发现sort()函数有一个问题,sort排序只会返回排序后的结果,不会返回每个排序后的结果在原来的编号。//template
bool cmp(const pair &x,const pair &y)
{
return x.second > y.second;
}
//template
void sortVector(vector &value, vector...
分类:
编程语言 时间:
2015-07-06 21:48:37
阅读次数:
133
#include
int max_2(int a,int b)
{
return a>b?a:b;
}
int max_4(int a,int b,int c,int d)
{
int m;
m = max_2(a,b);
m = max_2(m,c);
m = max_2(m,d);
return m;
}
int main()
{
int a,b,c,d;
printf("p...
分类:
其他好文 时间:
2015-07-06 21:46:40
阅读次数:
99
power-of-two
class Solution {
public:
bool isPowerOfTwo(int n) {
return n>=1 && !(n&(n-1));
}
};
n=10000***000,
n&(n-1)=0
是这个方法的核心...
分类:
其他好文 时间:
2015-07-06 21:45:50
阅读次数:
117
题目描述
链接地址
解法题目描述Find the nth to last element of a singly linked list. The minimum number of nodes in list is n.
ExampleGiven a List 3->2->1->5->null and n = 2, return node whose value is 1.链接地址http...
分类:
其他好文 时间:
2015-07-06 21:45:46
阅读次数:
122
方法一:/** * 该View绘制到Bitmap上 * @param view 须要绘制的View * @param width 该View的宽度 * @param height 该View的高度 * @return 返回Bitmap对象 * add by csj 13-11-6 */ public...
分类:
其他好文 时间:
2015-07-06 21:29:40
阅读次数:
118
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu...
分类:
其他好文 时间:
2015-07-06 21:18:48
阅读次数:
101