Created
March 25, 2019 18:31
-
-
Save ykdojo/7b6d637479dcace031bcea62e8ee8a79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* function TreeNode(val) { | |
* this.val = val; | |
* this.left = this.right = null; | |
* } | |
*/ | |
/** | |
* @param {TreeNode} root | |
* @return {boolean} | |
*/ | |
var isUnivalTree = function(root) { | |
return helper(root, root.val); | |
}; | |
var helper = function(root, val) { | |
if (!root) { | |
return true; | |
} | |
if (root.val != val) { | |
return false; | |
} | |
if (!helper(root.left, val) || !helper(root.right, val)) { | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment