Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int traverse(TreeNode root) {
- int val = 0;
- if(root == null)
- return 0;
- if (root.left != null) {
- val += traverse(root.left.left) + traverse(root.left.right);
- }
- if (root.right != null) {
- val += traverse(root.right.left) + traverse(root.right.right);
- }
- return Math.max(val + root.val, traverse(root.left) + traverse(root.right));
- }
- public int rob(TreeNode root) {
- return traverse(root);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement