Univalued Binary Tree (Leetcode 965)
Technique: FAITH technique of Recursion
Problem Link: https://leetcode.com/problems/univalued-binary-tree/
class Solution:
def isUnivalTree(self, root: Optional[TreeNode]) -> bool:
def fun(root, value):
if(root is None):
return True
l=fun(root.left,value)
r=fun(root.right,value)
if(l and r and root.val==value):
return True
return False
return fun(root, root.val)
Last updated