package leetcode;

/**
 * https://leetcode.com/problems/count-good-nodes-in-binary-tree/
 */
public class Problem1448 {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

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

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

        TreeNode root = new TreeNode(3);
        root.left = new TreeNode(1);
        root.left.left = new TreeNode(3);
        root.right = new TreeNode(4);
        System.out.println(prob.goodNodes(root)); // 4

        root = new TreeNode(3);
        root.left = new TreeNode(3);
        root.left.left = new TreeNode(4);
        root.left.right = new TreeNode(2);
        System.out.println(prob.goodNodes(root)); // 3

        root = new TreeNode(1);
        System.out.println(prob.goodNodes(root)); // 1
    }
}

@@ -532,32 +532,311 @@
     
-// TODO%0A        return 0
+return goodNodes(root, Integer.MIN_VALUE);%0A    %7D%0A%0A    private static int goodNodes(TreeNode root, int parent) %7B%0A        if (root == null) %7B%0A            return 0;%0A        %7D%0A        int val = root.val %3E= parent ? 1 : 0;%0A        return goodNodes(root.left, root.val) + goodNodes(root.right, root.val) + val
 ;%0A  
@@ -965,32 +965,34 @@
 ew TreeNode(3);%0A
+//
         root.lef
@@ -1004,32 +1004,34 @@
 ew TreeNode(1);%0A
+//
         root.lef
@@ -1048,32 +1048,34 @@
 ew TreeNode(3);%0A
+//
         root.rig
@@ -1088,32 +1088,125 @@
 ew TreeNode(4);%0A
+//        root.right.left = new TreeNode(1);%0A//        root.right.right = new TreeNode(5);%0A//
         System.o
@@ -1302,36 +1302,334 @@
  = new TreeNode(
-3);%0A
+1);%0A        root.left.left = new TreeNode(1);%0A        root.right = new TreeNode(4);%0A        root.right.left = new TreeNode(1);%0A        root.right.right = new TreeNode(5);%0A        System.out.println(prob.goodNodes(root)); // 3%0A%0A//        root = new TreeNode(3);%0A//        root.left = new TreeNode(3);%0A//
         root.lef
@@ -1646,32 +1646,34 @@
 ew TreeNode(4);%0A
+//
         root.lef
@@ -1699,16 +1699,18 @@
 ode(2);%0A
+//
         
@@ -1756,17 +1756,293 @@
 ); // 3%0A
-%0A
+//%0A//        root = new TreeNode(3);%0A//        root.left = new TreeNode(3);%0A//        root.left.left = new TreeNode(4);%0A//        root.left.right = new TreeNode(2);%0A//        root.left.right.left = new TreeNode(3);%0A//        System.out.println(prob.goodNodes(root)); // 4%0A//%0A//
         
@@ -2057,32 +2057,34 @@
 ew TreeNode(1);%0A
+//
         System.o

Update problem 1448