luoheng
10/6/2019 - 2:43 PM

isUnivalTree

/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
func isUnivalTree(root *TreeNode) bool {
    if root == nil {
        return true
    }
    if root.Left != nil && root.Left.Val != root.Val || root.Right != nil && root.Right.Val != root.Val {
        return false
    }
    return isUnivalTree(root.Left) && isUnivalTree(root.Right)
}