标签:
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; } }
[LeetCode]Count Univalue Subtrees
标签:
原文地址:http://www.cnblogs.com/vision-love-programming/p/5004614.html