private static bool Helper(LeetCode250TreeNode root, int val) { if (root == null) { return(true); } if (!Helper(root.left, root.val) | !Helper(root.right, root.val)) { return(false); } count++; return(root.val == val); }
public static int CountUnivalSubTree(LeetCode250TreeNode root) { Helper(root, 0); return(count); }
public LeetCode250TreeNode(int val = 0, LeetCode250TreeNode left = null, LeetCode250TreeNode right = null) { this.val = val; this.left = left; this.right = right; }