qingcheng奕  
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 23 下一页

2014年1月11日

摘要: http://oj.leetcode.com/problems/search-for-a-range/要求复杂度为O(lgn),用二分查找的思想。#include #include using namespace std;class Solution {public: void fun(int* A,int start,int end,int target,vector &ans) { if(start>end || ( start == end && A[start]!= target )) { ans.push_back(-1)... 阅读全文
posted @ 2014-01-11 17:49 qingcheng奕 阅读(131) 评论(0) 推荐(0) 编辑
 
摘要: #include using namespace std;class Reader{public: Reader() { xCoordinate = NULL; xCoordinate = (int*)malloc(sizeof(int)*100); coutDoHandle(); delete p3Converter; //不调用Reader2的构造和析构 Converter *p3Converter = new Converter(); delete p3Converter; return 0;} 阅读全文
posted @ 2014-01-11 15:40 qingcheng奕 阅读(338) 评论(0) 推荐(0) 编辑

2014年1月9日

摘要: F5 开始调试,执行到断点Shift + F5 停止调试F9 在光标所在行添加断点Shift + F9 QuickWatchShift Ctrl F9 delete all 断点F10 单步执行F11 进入调用的函数Shift F11 跳出这次调用的函数另外还可以用Disable all breakpoints可以右键点击添加breakpoint condition.比如 int i = 0; 条件可以是 i==5,或者 i has changed.如果 string str,则可以 strcmp(str,"onestring") ==0这样的。对于char *str ;s 阅读全文
posted @ 2014-01-09 22:41 qingcheng奕 阅读(1730) 评论(0) 推荐(0) 编辑
 
摘要: http://oj.leetcode.com/problems/add-two-numbers/将用链表表示的两个数相加,(2 -> 4 -> 3) + (5 -> 6 -> 4) 就是342 + 465.刚开始把题目给理解错了,做复杂了。主要是对指针的理解。ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reus.. 阅读全文
posted @ 2014-01-09 20:33 qingcheng奕 阅读(133) 评论(0) 推荐(0) 编辑

2014年1月7日

摘要: http://oj.leetcode.com/problems/regular-expression-matching/问题给想复杂了,只有p中可以含有. *,s中的字符都是确定的。想了好久,最终还是参考了网上的答案。等我再想想。#include #include #include using namespace std;class Solution {public: bool isMatch(const char *s, const char *p) { if (s == NULL || p == NULL) return false; if ... 阅读全文
posted @ 2014-01-07 16:20 qingcheng奕 阅读(170) 评论(0) 推荐(0) 编辑

2014年1月6日

摘要: http://oj.leetcode.com/problems/roman-to-integer/罗马数字到自然数字的转换,先自己查相关的背景知识,然后分析清楚了。可以简化写,嗯嗯。“简化”,抓到本质。#include #include #include using namespace std;class Solution {public: int change(char ch) { int num = 0; switch(ch) { case 'I': num = 1; break... 阅读全文
posted @ 2014-01-06 19:04 qingcheng奕 阅读(155) 评论(0) 推荐(0) 编辑

2014年1月3日

摘要: 最近在学动态规划,初略一看以为动态规划来了,但是一分析发现不具备最优子结构,所以不是动态规划。那么对左边界和长度做个两层循环,遍历所有的可能,复杂度为O(n2),代码如下:class Solution {public: int largestRectangleArea(vector &height) { int smallest; int ans = 0; int size; for(int i = 0;iheight[i+j-1]) { smallest = h... 阅读全文
posted @ 2014-01-03 19:32 qingcheng奕 阅读(159) 评论(0) 推荐(0) 编辑

2014年1月2日

摘要: http://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/这三道题,很好的进阶。1题简单处理,2题使用贪心,3题使用动态规划。话说这叫一维动态规划,嗯。又复习了《算法导论》中和贪心以及动态规划有关的知识,记录如下:动态规划的标志:最优子结构、子问题重叠。 1.找最优子结构 2.定义递归公示(列一个式子出来,并定义好这个式子到底是什么意思)。 3.写自底向上或递归备忘录法。比如本问题:f(i,j) = max{f(i,k)+f(k,j)} 其中:f(i,j)表示从i到j的所有数,进行一次交易能获得... 阅读全文
posted @ 2014-01-02 19:00 qingcheng奕 阅读(171) 评论(0) 推荐(0) 编辑
 
摘要: http://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/第二问,是说可以进行无数次买卖。贪心法#include #include using namespace std;class Solution {public: int maxProfit(vector &prices) { if(prices.empty()) return NULL; if(prices.size()==1) return 0; int ans = 0... 阅读全文
posted @ 2014-01-02 15:51 qingcheng奕 阅读(197) 评论(0) 推荐(0) 编辑

2014年1月1日

摘要: 找一个数后面最大的数,求出一列数中这样的最大差值。首先想到了两层循环O(n*n)复杂度。然后超时,代码如下:class Solution {public: int maxProfit(vector &prices) { if(prices.empty()) return NULL; if(prices.size()==1) return 0; int ans = 0; for(int i = 0;imax) max = prices[j... 阅读全文
posted @ 2014-01-01 16:44 qingcheng奕 阅读(133) 评论(0) 推荐(0) 编辑
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 23 下一页