1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
class Solution { int val = -1;
public boolean isUnivalTree(TreeNode root) { if (val == -1) val = root.val; if (root == null) return true; if (root.val != val) return false; return isUnivalTree(root.left) && isUnivalTree(root.right); } }
|