解题的关键在于这条路径只能是先往上走,到达某个最高点,再往下走,换句话说,只能有一次转折的机会。所以递归这棵树,记录以某个子节点为转折点时的最大值。值得注意的是树节点的值有负值,所以如果某个子路径的和小于0,放弃它(设置和为0)。
class Solution {
public:
int maxPathSum(TreeNode *root) {
int maxSum = -1 <...
分类:
其他好文 时间:
2014-08-23 10:01:00
阅读次数:
167
https://oj.leetcode.com/problems/edit-distance/Edit DistanceGiven two wordsword1andword2, find the minimum number of steps required to convertword1tow...
分类:
编程语言 时间:
2014-08-23 09:56:50
阅读次数:
213
HDFS Rolling Upgrade
Introduction
HDFS 滚动升级允许单独升级每一个HDFS进程。例如,DataNode可以独立于NameNode升级。一个NameNode可以独立于其他的NameNode升级。NameNode可以独立于DataNode和JournalNode升级。
Upgrade
在Hadoop V2中,HDFS支持NameNode服务的HA和前后兼容...
分类:
其他好文 时间:
2014-08-22 10:51:26
阅读次数:
172
算是最长公共子序列问题吧,mark一下
class Solution {
public:
bool f[1000][1000];
bool isInterleave(string s1, string s2, string s3) {
if(s1.size() + s2.size() != s3.size())
return false;
...
分类:
其他好文 时间:
2014-08-21 22:51:34
阅读次数:
185
First I thought of a DP solution.. but TLE. So there must be a O(n). I thought of Mono-Queue.. but looks too complex.So what is the naive solution? O(...
分类:
其他好文 时间:
2014-08-21 14:37:54
阅读次数:
202
最近在给客户基于Suse 11 sp3安装Oracle 10g RAC,在安装完clusterware执行/u01/app/crs/root.sh时收到错误提示,Failed to upgrade Oracle Cluster Registry configuration由于当前的环境使用了多路径,从Oracle的描述来看,这是一个Oracle Bug(4679769),如果你有相同的问题,请接着...
分类:
数据库 时间:
2014-08-21 13:28:24
阅读次数:
381
1A! We get median of each array and compare them, then we know which half should be disguarded and how many should be disguarded.class Solution {publi...
分类:
其他好文 时间:
2014-08-21 13:13:24
阅读次数:
191
A classic and representative DP problem. To be revised later. Quite a few interesting details to think about.class Solution {public: int numDistinc...
分类:
其他好文 时间:
2014-08-21 13:03:34
阅读次数:
180
Implement pow(x, n).刚开始没想到,后来看remlost的博客才写出来,代码很简练:class Solution {public: double pow(double x, int n) { if(n<0) return 1/power(x...
分类:
其他好文 时间:
2014-08-21 10:59:53
阅读次数:
188
Follow up for problem "Populating Next Right Pointers in Each Node".
What if the given tree could be any binary tree? Would your previous solution still work?
Note:
You may only use constant extr...
分类:
其他好文 时间:
2014-08-20 22:47:33
阅读次数:
297