Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Tested Python solution for LeetCode 965 with 20 pytest cases. Generate a practice environment with lcpy.
lcpy gen -n 965 # by problem number lcpy gen -s univalued_binary_tree # by problem name
Input: root = [1,1,1,1,1,null,1] Output: true
Input: root = [2,2,2,5,2] Output: false
from leetcode_py import TreeNode class Solution: # Time: O(n) # Space: O(h) def is_unival_tree(self, root: TreeNode[int] | None) -> bool: if root is None: return True stack = [root] target = root.val while stack: node = stack.pop() if node.val != target: return False if node.left is not None: stack.append(node.left) if node.right is not None: stack.append(node.right) return True