binary Tree2 LeetCode. Count Complete Tree Nodes Problem: Given a complete binary tree, count the number of nodes. Note: Definition of a complete binary tree from Wikipedia: In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h. Example: -Summary- Solve by recursion 1. if the root exists.. 2020. 6. 24. LeetCode 226. Invert Binary Tree Problem: Invert a binary tree. Example: -Summary- Solved recursively 1. Until root node exist, we keep traverse left and right and change the left and right subtree by exchanging value. (By calling the function recursively) Here is another solution by solving this iteratively using stack. def invertTree(self, root): stack = [root] while stack: node = stack.pop() if node: node.left, node.right = .. 2020. 6. 20. 이전 1 다음