标签:技术 max problem pre https val use tps solution
https://leetcode-cn.com/problems/house-robber-iii/solution/da-jia-jie-she-iii-by-leetcode-solution/
class Solution {
public:
unordered_map <TreeNode*, int> f, g;
void dfs(TreeNode* o) {
if (!o) {
return;
}
dfs(o->left);
dfs(o->right);
f[o] = o->val + g[o->left] + g[o->right];
g[o] = max(f[o->left], g[o->left]) + max(f[o->right], g[o->right]);
}
int rob(TreeNode* o) {
dfs(o);
return max(f[o], g[o]);
}
};
标签:技术 max problem pre https val use tps solution
原文地址:https://www.cnblogs.com/Hunter01/p/13443112.html