Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement