摘要: https://oj.leetcode.com/problems/unique-binary-search-trees-ii/跟二叉树个数计数的那道题类似,不同的是需要把所有的可能都返回,并整合成结果。/** * Definition for binary tree * struct TreeNod... 阅读全文
posted @ 2014-10-19 16:47 zombies 阅读(141) 评论(0) 推荐(0) 编辑
摘要: https://oj.leetcode.com/problems/3sum-closest/和3sum类似。不同的是这次需要逼近一个值,实际上跟相等类似,用l和r指针不断移动,然后反复取最小即可。class Solution {public: int n,m; int threeSumC... 阅读全文
posted @ 2014-10-19 10:59 zombies 阅读(129) 评论(0) 推荐(0) 编辑
摘要: https://oj.leetcode.com/problems/powx-n/其实是很简单的递归就能解。每次将其降低到n/2即可。需要注意各种边界条件,包括n为最小的负数的情况。class Solution {public: double pow(double x, int n) { ... 阅读全文
posted @ 2014-10-19 02:19 zombies 阅读(142) 评论(0) 推荐(0) 编辑
摘要: https://oj.leetcode.com/problems/gas-station/计算每个加油站的加油差diff[]。得到一个数组。从贪心的角度来说,如果我们找到一个最大子串,那么从他的起点l开始走,能够连续一直走并且累积最大量的汽油。一个猜想是:如果这些汽油不足以走完全程,那么无论从哪里都... 阅读全文
posted @ 2014-10-19 02:05 zombies 阅读(246) 评论(0) 推荐(0) 编辑
摘要: https://oj.leetcode.com/problems/maximum-subarray/一直累加子串并求最大。当子串小于0时就抛弃掉,这样总能找到最大的那个子串和。class Solution {public: int maxSubArray(int A[], int n) { ... 阅读全文
posted @ 2014-10-19 01:34 zombies 阅读(154) 评论(0) 推荐(0) 编辑
摘要: https://oj.leetcode.com/problems/distinct-subsequences/首先要理解题目:count the number of distinct subsequences ofTinS.意思是,数出T在S的唯一子序列的个数。也就是有多少个S的子序列是T。子序列可... 阅读全文
posted @ 2014-10-19 00:41 zombies 阅读(236) 评论(0) 推荐(0) 编辑