package leetcode;

/**
 * https://leetcode.com/problems/house-robber-iii/
 */
public class Problem337 {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public int rob(TreeNode root) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem337 prob = new Problem337();

        TreeNode root = new TreeNode(3);
        root.left = new TreeNode(2);
        root.left.right = new TreeNode(3);
        root.right = new TreeNode(3);
        root.right.right = new TreeNode(1);
        System.out.println(prob.rob(root)); // 7

        root = new TreeNode(3);
        root.left = new TreeNode(4);
        root.left.left = new TreeNode(1);
        root.left.right = new TreeNode(3);
        root.right = new TreeNode(5);
        root.right.right = new TreeNode(1);
        System.out.println(prob.rob(root)); // 9
    }
}

@@ -325,16 +325,445 @@
     
-return 0
+int a = rob(root, false);%0A        int b = rob(root, true);%0A        System.out.println(a + %22 vs %22 + b);%0A        return Math.max(a, b);%0A    %7D%0A%0A    private int rob(TreeNode node, boolean skip) %7B%0A        if (node == null) %7B%0A            return 0;%0A        %7D%0A        int val = 0;%0A        if (!skip) %7B%0A            val = node.val;%0A        %7D%0A        int a = rob(node.left, !skip);%0A        int b = rob(node.right, !skip);%0A        return a + b + val
 ;%0A  
@@ -1338,32 +1338,32 @@
 ew TreeNode(1);%0A
-
         System.o
@@ -1394,16 +1394,224 @@
 )); // 9
+%0A%0A        root = new TreeNode(4);%0A        root.left = new TreeNode(1);%0A        root.left.left = new TreeNode(2);%0A        root.left.left.left = new TreeNode(3);%0A        System.out.println(prob.rob(root)); // 7
 %0A    %7D%0A%7D

Update problem 337