Pow(x, n)
可以直接用库函数pow(x,n)一步搞定,但明显这样就没意思了。
参考快速幂取模
二分,复杂度为O(logn)
递归方法
class Solution {
public:
double myPow(double x, int n) {
if(n<0) return 1.0/myPow_1(x,-n);
...
分类:
其他好文 时间:
2015-07-09 18:02:45
阅读次数:
92
过程:
int MoreThanHalfNum(int* numbers, int length)
{
if (CheckInvalidArray(numbers, length))
return 0;
int middle = length >> 1;
int start = 0;
int end = length - 1;
int index = Partition(numbe...
分类:
编程语言 时间:
2015-07-09 18:02:10
阅读次数:
136
void GetLeastNumbers(int* input, int n, int* output, int k)
{
if (input == NULL || output == NULL || k > n || n
return;
int start = 0;
int end = n - 1;
int index = Partition(input, n, start, en...
分类:
其他好文 时间:
2015-07-09 18:01:10
阅读次数:
156
题目:
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).
For example:
Give...
分类:
编程语言 时间:
2015-07-09 17:59:13
阅读次数:
112
解法一:递归int countNodes(TreeNode* root){ if (root == NULL) return 0; TreeNode *pLeft = root->left; TreeNode *pRight = root->right; ...
分类:
其他好文 时间:
2015-07-09 17:55:25
阅读次数:
126
对于co的一个最简版的实现,代码如下 (https://gist.github.com/iwillwen/8488050)function co(generator) { return function(fn) { var gen = generator(); function nex...
分类:
其他好文 时间:
2015-07-09 17:52:04
阅读次数:
123
模型:WeChatfind($mid); } /** * 处理来自微信服务器的消息 * @param $callback * @access public * @return void */ static public function pr...
分类:
微信 时间:
2015-07-09 17:43:48
阅读次数:
480
void DoEvents(){ MSG msg; // Process existing messages in the application's message queue. // When the queue is empty, do clean up and return...
分类:
其他好文 时间:
2015-07-09 17:32:25
阅读次数:
105
修改main.m文件
#import
#import "Root.h"
int main(int argc, const char * argv[])
{
@autoreleasepool
{
Root *rt = [[Root alloc] init];
[rt desc];
}
return 0;
}
OC文件:Root....
分类:
编程语言 时间:
2015-07-09 16:15:42
阅读次数:
122
void Permutation(char* pStr)
{
if (pStr == NULL)
return;
Permutation(pStr, pStr);
}
void Permutation(char* pStr, char* pBegin)
{
if (*pBegin == '\0')
{
printf("%s\n", pStr);
}
else
{
fo...
分类:
其他好文 时间:
2015-07-09 16:09:51
阅读次数:
120