N-Queens II
摘要: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)
N-Queens
摘要:题目的要点是:怎么快速判断这次的皇后和以前的是不冲突的。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)
Letter Combinations of a Phone Number
摘要: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)
Combinations
摘要: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)
Longest Valid Parentheses
摘要:难点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)
Pow(x, n)
摘要:这道题关键点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)
Intersection of Two Linked Lists
摘要:该题目对内存的使用极其变态。所用变量不能超过4个。否侧会内存超限。解法有两个,其中第二种解法,内存还需要优化,否则会内存越界。解法一:class Solution {public: ListNode *getIntersectionNode(ListNode *headA, ListNode ...
阅读全文
posted @
2015-01-08 21:36
xgcode
阅读(98)
推荐(0)
String to Integer (atoi)
摘要:这道题知道了用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
阅读(149)
推荐(0)
Search for a Range
摘要:这道题没什么好说的,二分法查找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)
Word Ladder II
摘要:这道题做了好长时间都没通过,参考了http://blog.csdn.net/niaokedaoren/article/details/8884938的实现,其中在求前驱单词记录时,申请的数组要采用vector>这样,在判断是否结束时,查找效率更高,否则用前向单词记录表查找时效率会很低。算法中的递归找...
阅读全文
posted @
2015-01-01 13:52
xgcode
阅读(162)
推荐(0)