上一页 1 ··· 6 7 8 9 10 11 下一页
Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No... Read More
posted @ 2014-10-24 13:04 chengcy Views(138) Comments(0) Diggs(0)
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single ... Read More
posted @ 2014-10-23 20:44 chengcy Views(134) Comments(0) Diggs(0)
Suppose a sorted array is rotated at some pivot unknown to you beforehand.ie:0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2you are given a target value to s... Read More
posted @ 2014-10-02 10:35 chengcy Views(158) Comments(0) Diggs(0)
Follow up the "remove duplicates",what if duplicates are allowed at most twice?思路一:使用变量numlength记录数组中相同数字出现不超过两次所得到的数组长度;code:class Solution {public: ... Read More
posted @ 2014-09-30 21:29 chengcy Views(216) Comments(0) Diggs(0)
内联函数:可以避免函数调用的开销;内联函数和宏很类似,而区别在于,宏是由预处理器对宏进行替代,而内联函数是通过编译器控制来实现的。而且内联函数是真正的函数,只是在需要用到的时候,内联函数像宏一样的展开,所以取消了函数的参数压栈,减少了调用的开销。你可以象调用函数一样来调用内联函数,而不必担心会产生于... Read More
posted @ 2014-09-04 13:23 chengcy Views(180) Comments(0) Diggs(0)
方法一:从根节点开始,将每层节点压入一个数组,cur代表当前访问节点,last代表下一层第一个节点,遍历数组可得层次遍历;代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 template 7 class ... Read More
posted @ 2014-08-31 20:16 chengcy Views(253) Comments(0) Diggs(0)
方法一:使用递归思想代码: 1 #include 2 #include 3 using namespace std; 4 5 int minValue(int t1,int t2,int t3); 6 int calculateStringDistance(string strA,int pAbe... Read More
posted @ 2014-08-31 20:14 chengcy Views(209) Comments(0) Diggs(0)
题目要求输出“将”(A),“帅”(B)的所有合法位置,并且只能使用一个字节存储变量;解法一: 1 #include 2 using namespace std; 3 4 int main() 5 { 6 int i=81; 7 while(i--) 8 { 9 ... Read More
posted @ 2014-08-28 14:07 chengcy Views(155) Comments(0) Diggs(0)
关于递归程序:递归程序结构包括三部分:递归出口、逻辑处理(需要处理的问题)、递归调用(衔接)。通过递归调用将问题转化为对子问题的解决,通过回溯完成原问题的解答;递归与数学归纳法:递归是数学归纳法在计算机程序中的体现。使用递归思想设计程序时,我们设置base case,并假设我们会获得n-1的结果,并... Read More
posted @ 2014-08-24 15:04 chengcy Views(408) Comments(0) Diggs(0)
将源区间按照x坐标大小排序,然后进行合并,使用二分查找目标区间x,y坐标在源区间中的分布,若两者分布于同一连续区间,则区间重合代码: 1 #include 2 #include 3 using namespace std; 4 5 struct section 6 { 7 int low;... Read More
posted @ 2014-08-23 13:35 chengcy Views(329) Comments(0) Diggs(0)
上一页 1 ··· 6 7 8 9 10 11 下一页