← 返回 sofi 的题目列表Binary Tree with 0 and 1 Values
类型:online_judge
Given a binary tree where each node has a value of 0 or 1, and an initial height h where all nodes start with a value of 0, implement two operations: set(index) to set the leaf node's value as 1 and clear(index) to reset the leaf node's value to 0. If a node's left and right children both are 1, its value should also be set to 1. Ensure all operations complete in O(h) time.
Example
Input
set(index=3)