Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 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.Right != nil && root.Val != root.Right.Val) ||
- (root.Left != nil && root.Val != root.Left.Val) {
- return false
- }
- return isUnivalTree(root.Left) && isUnivalTree(root.Right)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement