qingcheng奕  
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 23 下一页

2014年6月18日

摘要: https://oj.leetcode.com/problems/minimum-path-sum/对一个grid从左上角到右下角的路径,求出路径中和最小的。受之前思路的影响,就寻思递归,并且记录中间过程的数据,这样避免重复计算。但是超时了。class Solution {public: in... 阅读全文
posted @ 2014-06-18 20:55 qingcheng奕 阅读(161) 评论(0) 推荐(0) 编辑
 
摘要: https://oj.leetcode.com/problems/unique-paths-ii/图的深搜,有障碍物,有的路径不通。刚开始想的时候用组合数算,但是公式没有推导出来。于是用了深搜,递归调用。但是图最大是100*100,太大了,超时。考虑到在计算(2,1)和(1,2)都用到了(2,2),... 阅读全文
posted @ 2014-06-18 10:57 qingcheng奕 阅读(163) 评论(1) 推荐(0) 编辑

2014年6月17日

摘要: https://oj.leetcode.com/problems/unique-paths/首先,转换成一个排列组合问题,计算组合数C(m+n-2) (m-1),请自动想象成上下标。class Solution {public: int uniquePaths(int m, int n) { ... 阅读全文
posted @ 2014-06-17 20:01 qingcheng奕 阅读(169) 评论(1) 推荐(0) 编辑
 
摘要: https://oj.leetcode.com/problems/path-sum-ii/树的深搜,从根到叶子,并记录符合条件的路径。注意参数的传递,是否需要使用引用。#include #include using namespace std;struct TreeNode { int va... 阅读全文
posted @ 2014-06-17 09:45 qingcheng奕 阅读(170) 评论(0) 推荐(0) 编辑

2014年6月16日

摘要: https://oj.leetcode.com/problems/path-sum/树的深搜,求从根到叶子的路径。记住深搜的样子#include using namespace std;struct TreeNode { int val; TreeNode *left; Tr... 阅读全文
posted @ 2014-06-16 09:07 qingcheng奕 阅读(141) 评论(0) 推荐(0) 编辑

2014年6月15日

摘要: https://oj.leetcode.com/problems/sort-colors/0,1,2对这三个数组成的序列,扫描一遍的排序。class Solution {public: void sortColors(int A[], int n) { int x = -1, y... 阅读全文
posted @ 2014-06-15 18:29 qingcheng奕 阅读(107) 评论(0) 推荐(0) 编辑

2014年6月14日

摘要: https://oj.leetcode.com/problems/single-number-ii/有一列数,其中有1个数的个数不是3的倍数,求出这个数。学习了别人的思路,按照二进制,统计每个位上1的个数,3个相同的数的话,它们的二进制表示是相同的,则同一个位置上,必然1的个数是3,所以 % 3,变... 阅读全文
posted @ 2014-06-14 21:23 qingcheng奕 阅读(105) 评论(0) 推荐(0) 编辑
 
摘要: https://oj.leetcode.com/problems/single-number/给一个数列,其中只有一个数不是两两相同的,在O(n)时间内求出来,并且不使用额外空间。使用异或操作,如果是两个相同的数异或的话,就都消去了。异或操作的单位元是0.#include using namespa... 阅读全文
posted @ 2014-06-14 09:57 qingcheng奕 阅读(121) 评论(0) 推荐(0) 编辑
 
摘要: https://oj.leetcode.com/problems/subsets-ii/求一个集合的子集,但集合中有重复元素。求子集的问题,对应着数的二进制,相当于对二进制的一个遍历。#include #include #include using namespace std;class Solut... 阅读全文
posted @ 2014-06-14 09:46 qingcheng奕 阅读(140) 评论(0) 推荐(0) 编辑

2014年6月13日

摘要: https://oj.leetcode.com/problems/zigzag-conversion/将字符串Z形字排列后,再重新一行一行输出。可以找到每一行字符位置的规律,然后填充进去。敲代码之前,先演算好了,每个变量是怎样表达的,规律到底是什么样的。#include #include #incl... 阅读全文
posted @ 2014-06-13 21:53 qingcheng奕 阅读(134) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 23 下一页