2015年2月1日
摘要: 求解回文字符串:这道题是查找资料才得到的解法。具体思路如下:比如对字符串abcba,做如下处理#a#b#c#b#a#,目的是消除偶数的回文。计算一点的回文长度时,根据保存的前端的最大回文长度和中心点,判断当前点应该是从0开始计算,还是可以根据利用以前的结果。主要就是这个思路。class Soluti... 阅读全文
posted @ 2015-02-01 12:55 xgcode 阅读(129) 评论(0) 推荐(0)
  2015年1月17日
摘要: class Solution {public: vector hor; vector ver; vector rightline; vector leftline; int len; int result; int totalNQueens(int n) { result ... 阅读全文
posted @ 2015-01-17 14:19 xgcode 阅读(111) 评论(0) 推荐(0)
摘要: 题目的要点是:怎么快速判断这次的皇后和以前的是不冲突的。class Solution {public: vector hor; vector ver; vector rightline; vector leftline; int len; vector> result; vector >... 阅读全文
posted @ 2015-01-17 13:48 xgcode 阅读(129) 评论(0) 推荐(0)
摘要: class Solution {public: vector result; vector letterCombinations(string digits) { string buf[] = { "abc","def","ghi","jkl","mno","pqrs","tuv... 阅读全文
posted @ 2015-01-17 10:45 xgcode 阅读(89) 评论(0) 推荐(0)
摘要: class Solution {public: vector> result; vector temp; vector > combine(int n, int k) { temp.resize(k); GetCombine(n,k); return result; } ... 阅读全文
posted @ 2015-01-17 10:09 xgcode 阅读(124) 评论(0) 推荐(0)
  2015年1月11日
摘要: 难点1,是栈,2是流程class Solution {public: int longestValidParentheses(string s) { stack mstack; char cbefore; int count = 0; if(s.empt... 阅读全文
posted @ 2015-01-11 11:39 xgcode 阅读(102) 评论(0) 推荐(0)
  2015年1月9日
摘要: 这道题关键点class Solution {public: double pow(double x, int n) { double result =1; int index = abs(n); for(int i=0; i 0) { ... 阅读全文
posted @ 2015-01-09 21:15 xgcode 阅读(105) 评论(0) 推荐(0)
  2015年1月8日
摘要: 该题目对内存的使用极其变态。所用变量不能超过4个。否侧会内存超限。解法有两个,其中第二种解法,内存还需要优化,否则会内存越界。解法一:class Solution {public: ListNode *getIntersectionNode(ListNode *headA, ListNode ... 阅读全文
posted @ 2015-01-08 21:36 xgcode 阅读(98) 评论(0) 推荐(0)
  2015年1月1日
摘要: 这道题知道了用long long 这种变量类型,从最初的128ms优化到68ms代码如下:class Solution {public: int atoi(const char *str) { if(str == NULL) return 0; int i=0; int f... 阅读全文
posted @ 2015-01-01 19:13 xgcode 阅读(150) 评论(0) 推荐(0)
摘要: 这道题没什么好说的,二分法查找class Solution {public: vector range; vector searchRange(int A[], int n, int target) { range.push_back(-1); range.push_b... 阅读全文
posted @ 2015-01-01 16:43 xgcode 阅读(100) 评论(0) 推荐(0)