problemscpp
A collection of my answers to algorithm problems in c++.
Public 成员函数 | Private 属性 | 所有成员列表
leetcode::house_robber_iii::Solution类 参考

#include <leetcode.h>

Public 成员函数

int dfs (bool steal, TreeNode *node)
 
int rob (TreeNode *root)
 

Private 属性

unordered_map< pair< TreeNode *, bool >, int, myhash, myequm
 

详细描述

在文件 leetcode.h3083 行定义.

成员函数说明

◆ dfs()

int leetcode::house_robber_iii::Solution::dfs ( bool  steal,
TreeNode node 
)

在文件 leetcode.cpp8709 行定义.

8709 {
8710 if(um.contains({node, steal})) {
8711 return um[{node, steal}];
8712 }
8713 int ans = steal ? node->val : 0;
8714 if(node->left != nullptr) {
8715 const int ns = dfs(!steal, node->left);
8716 const int s = !steal ? dfs(steal, node->left) : 0;
8717 ans += max(s, ns);
8718 }
8719 if(node->right != nullptr) {
8720 const int ns = dfs(!steal, node->right);
8721 const int s = !steal ? dfs(steal, node->right) : 0;
8722 ans += max(s, ns);
8723 }
8724 um[{node, steal}] = ans;
8725 return ans;
8726 }
int dfs(bool steal, TreeNode *node)
Definition: leetcode.cpp:8709
unordered_map< pair< TreeNode *, bool >, int, myhash, myeq > um
Definition: leetcode.h:3084

引用了 dfs(), leetcode::TreeNode::left, leetcode::TreeNode::right, um , 以及 leetcode::TreeNode::val.

被这些函数引用 dfs() , 以及 rob().

◆ rob()

int leetcode::house_robber_iii::Solution::rob ( TreeNode root)

在文件 leetcode.cpp8704 行定义.

8704 {
8705 int ans = 0;
8706 return max(dfs(true, root), dfs(false, root));
8707 }
vector< int > root
Definition: acwing408.cpp:349

引用了 dfs() , 以及 acwing::acwing836_408::root.

类成员变量说明

◆ um

unordered_map<pair<TreeNode *, bool>, int, myhash, myeq> leetcode::house_robber_iii::Solution::um
private

在文件 leetcode.h3084 行定义.

被这些函数引用 dfs().


该类的文档由以下文件生成: