SHARE
TWEET

Untitled

a guest Aug 25th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Definition for a binary tree node.
  3.  * type TreeNode struct {
  4.  *     Val int
  5.  *     Left *TreeNode
  6.  *     Right *TreeNode
  7.  * }
  8.  */
  9. func isUnivalTree(root *TreeNode) bool {
  10.     if root == nil {
  11.         return true
  12.     }
  13.     if (root.Right != nil && root.Val != root.Right.Val) ||
  14.     (root.Left != nil && root.Val != root.Left.Val) {
  15.     return false
  16.     }
  17.  
  18.     return isUnivalTree(root.Left) && isUnivalTree(root.Right)
  19. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top