[LeetCode]Count Univalue Subtrees
public class Solution { int result = 0; public int countUnivalSubtrees(TreeNode root) { helper(root); return result; } public boolean helper(TreeNode root) { if (root == null) { return true; } boolean left = helper(root.left); boolean right = helper(root.right); if ((left && (root.left == null || root.val == root.left.val)) && (right && (root.right == null || root.val == root.right.val))) { result ++; return true; } return false; } }