package com.fishercoder.solutions;

import com.fishercoder.common.classes.TreeNode;

/**
 * 965. Univalued Binary Tree
 *
 * A binary tree is univalued if every node in the tree has the same value.
 *
 * Return true if and only if the given tree is univalued.
 *
 * Example 1:
 *
 *         1
 *        / \
 *       1   1
 *      / \   \
 *     1  1   1
 *
 * Input: [1,1,1,1,1,null,1]
 * Output: true
 *
 *
 * Example 2:
 *        2
 *       / \
 *      2   2
 *     / \
 *    5  2
 *
 * Input: [2,2,2,5,2]
 * Output: false
 *
 *
 * Note:
 *
 * The number of nodes in the given tree will be in the range [1, 100].
 * Each node's value will be an integer in the range [0, 99].
 */
public class _965 {
  public static class Solution1 {
    public boolean isUnivalTree(TreeNode root) {
      if (root == null) {
        return true;
      }
      return dfs(root, root.val);
    }

    private boolean dfs(TreeNode root, int value) {
      if (root == null) {
        return true;
      }
      if (root.val != value) {
        return false;
      }
      return dfs(root.left, value) && dfs(root.right, value);
    }
  }
}

@@ -82,604 +82,8 @@
 e;%0A%0A
-/**%0A * 965. Univalued Binary Tree%0A *%0A * A binary tree is univalued if every node in the tree has the same value.%0A *%0A * Return true if and only if the given tree is univalued.%0A *%0A * Example 1:%0A *%0A *         1%0A *        / %5C%0A *       1   1%0A *      / %5C   %5C%0A *     1  1   1%0A *%0A * Input: %5B1,1,1,1,1,null,1%5D%0A * Output: true%0A *%0A *%0A * Example 2:%0A *        2%0A *       / %5C%0A *      2   2%0A *     / %5C%0A *    5  2%0A *%0A * Input: %5B2,2,2,5,2%5D%0A * Output: false%0A *%0A *%0A * Note:%0A *%0A * The number of nodes in the given tree will be in the range %5B1, 100%5D.%0A * Each node's value will be an integer in the range %5B0, 99%5D.%0A */%0A
 publ
@@ -98,16 +98,18 @@
  _965 %7B%0A
+  
   public
@@ -134,16 +134,20 @@
 tion1 %7B%0A
+    
     publ
@@ -183,24 +183,30 @@
 ode root) %7B%0A
+      
       if (ro
@@ -219,32 +219,40 @@
 null) %7B%0A        
+     
+   
 return true;%0A   
@@ -250,32 +250,44 @@
 true;%0A      
-%7D%0A
+      %7D%0A  
       
+    
 return dfs(r
@@ -310,15 +310,23 @@
     
-%7D%0A%0A
+    %7D%0A%0A   
     
+ 
 priv
@@ -365,24 +365,30 @@
 nt value) %7B%0A
+      
       if (ro
@@ -401,32 +401,40 @@
 null) %7B%0A        
+   
+     
 return true;%0A   
@@ -430,24 +430,30 @@
 n true;%0A
+      
       %7D%0A
       if
@@ -440,24 +440,30 @@
           %7D%0A
+      
       if (ro
@@ -485,24 +485,32 @@
 ) %7B%0A        
+     
+   
 return false
@@ -513,26 +513,38 @@
 alse;%0A      
-%7D%0A
+      %7D%0A      
       return
@@ -597,16 +597,22 @@
 e);%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 965