这个问题简单暴力的话会TLE,在这里我使用了筛法。 1 #include 2 #include
3 #define MAXN 36000 4 int m[MAXN]; 5 bool f[MAXN]; 6 int solve(int n){ 7
if(m[n]) return m[n]; ...
分类:
其他好文 时间:
2014-05-25 23:58:10
阅读次数:
409
一、定时器在cocos2d-x中,
类似定时器的操作,不需要额外的写Timer,实际上,在Node元素中,已经添加了定时执行的功能;先来看看在Node中的定义// ...bool
Node::isScheduled(SEL_SCHEDULE selector){ return _schedul...
分类:
其他好文 时间:
2014-05-25 19:42:54
阅读次数:
290
Implementint sqrt(int x).Compute and return the
square root ofx.思路:二分查找法解决这道题class Solution {public: int sqrt(int x) { if(x1e-6)
{ ...
分类:
其他好文 时间:
2014-05-25 19:35:33
阅读次数:
225
Remove Duplicates from Sorted ArrayGiven a
sorted array, remove the duplicates in place such that each element appear only
once and return the new len...
分类:
其他好文 时间:
2014-05-25 19:08:31
阅读次数:
203
题目:给定两个表示大数的字符串,求乘积,这里只针对正数。
分析:开始的时候打算一位一位的算,按着笔算的形式,但是写着写着发现太麻烦,后来在网上找到计算乘法的令一种技巧,感觉简洁多了。
先看代码,再分析。
string multiply(string num1, string num2) {
if(num1 == "0" || num2 == "0")
return "0";
//...
分类:
其他好文 时间:
2014-05-25 18:24:31
阅读次数:
195
【题目】
Given a list, rotate the list to the right by k places, where k is non-negative.
For example:
Given 1->2->3->4->5->NULL and k = 2,
return 4->5->1->2->3->NULL.
【题意】
给定一个链表L,和非负数K,要求把链表的后k个节点移到链表前
【思路】
先将指针指向指向倒数第K个节点,然后...
分类:
其他好文 时间:
2014-05-25 18:20:06
阅读次数:
252
【题目】
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.
If the last word does not exist, return 0.
Note: A word is defined as a character sequence consists of non-space ...
分类:
其他好文 时间:
2014-05-25 07:39:05
阅读次数:
256
【题目】
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
For example,
Given n = 3,
You should return the following matrix:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
]
【题意】
给定整数n, 将1,2,3...nxn个数按螺旋旋转的方式填入n...
分类:
其他好文 时间:
2014-05-25 07:08:17
阅读次数:
235
【题目】
The set [1,2,3,…,n] contains a total of n! unique permutations.
By listing and labeling all of the permutations in order,
We get the following sequence (ie, for n = 3):
"123"
"132"
"213"
"231"
"312"
"321"
Given n and k, return the kth permutation ...
分类:
其他好文 时间:
2014-05-25 06:13:37
阅读次数:
276
1. 一句话 :
js的闭包就是子函数可以使用父函数中的局部变量,这种行为就叫做闭包。2.例子js:function f(){ var a =5; function g(){
a++; return a; } }var h=f();var c =h();// c is 6var...
分类:
Web程序 时间:
2014-05-25 03:22:53
阅读次数:
213