Univalued Binary Tree | LeetCode | Java

tanujav

Tanuja V

Posted on May 29, 2024

Univalued Binary Tree | LeetCode | Java
class Solution {
    public boolean isUnivalTree(TreeNode root) {
        return checkUniValue(root, root.val);
    }

    boolean checkUniValue(TreeNode node, int val){
        if(node==null)
            return true;

        if(node.val!=val)
            return false;

        return (checkUniValue(node.left, val) && checkUniValue(node.right, val));
    }
}
Enter fullscreen mode Exit fullscreen mode

Thanks for reading :)
Feel free to comment and like the post if you found it helpful
Follow for more 🤝 && Happy Coding 🚀

If you enjoy my content, support me by following me on my other socials:
https://linktr.ee/tanujav7

💖 💪 🙅 🚩
tanujav
Tanuja V

Posted on May 29, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Two Sum solution.
beginners Two Sum solution.

April 9, 2021