Solved! Leetcode 2331. Evaluate Boolean Binary Tree

Table of ContentsDescription: Evaluate Boolean Binary Example 1Example 2ConstraintsSolutionTime ComplexitySpace Complexity Description: Evaluate Boolean Binary You are given the root of a full binary tree with the following properties: Leaf nodes have either the value 0 or 1, where 0 represents False and 1 represents True. Non-leaf nodes have either the value 2 or 3, where 2 represents the boolean OR and 3 represents the boolean AND. The evaluation of a node is as follows: If the node is a leaf node, the ...

Solved! Leetcode 623. Add One Row to Tree

Table of ContentsDescription Add One Row to TreeExample 1Example 2ConstraintsSolutionTime ComplexitySpace Complexity Description Add One Row to Tree Given the root of a binary tree and two integers val and depth, add a row of nodes with value val at the given depth depth. Note that the root node is at depth 1. The adding rule is: Given the integer depth, for each not null tree node cur at ...

Solved! Leetcode 404. Sum of Left Leaves

Description Sum of Left Leaves Table of ContentsDescription Sum of Left LeavesExample 1Example 2ConstraintsSolutionTime ComplexitySpace Complexity Given the root of a binary tree, return the sum of all left leaves. A leaf is a node with no children. A left leaf is a leaf that is the left child of another node. Example 1 <strong>Input:</strong> root = [3,9,20,null,null,15,7] <strong>Output:</strong> 24 <strong>Explanation:</strong> There ...

Solved! Leetcode 1161. Maximum Level Sum of a Binary Tree

Solved! Leetcode 1161. Maximum Level Sum of a Binary Tree
source: https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/description/ Table of ContentsMaximum Level Sum of a Binary TreeExample 1:Example 2:Constraints:Solution Maximum Level Sum of a Binary Tree Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum of all ...

Solved! Leetcode 1372. Longest ZigZag Path in a Binary Tree

source: https://leetcode.com/problems/longest-zigzag-path-in-a-binary-tree/description/ Longest ZigZag Path in a Binary Tree You are given the root of a binary tree. A ZigZag path for a binary tree is defined as follow: Choose any node in the binary tree and a direction (right or left). If the current direction is right, move to the right child of the ...

Solved! Leetcode 1485. Clone Binary Tree With Random Pointer

source: https://leetcode.com/problems/clone-binary-tree-with-random-pointer/description/ Clone Binary Tree With Random Pointer A binary tree is given such that each node contains an additional random pointer which could point to any node in the tree or null. Return a deep copy of the tree. The tree is represented in the same input/output way as normal binary trees where each ...

Solved! Leetcode 129. Sum Root to Leaf Numbers

source: https://leetcode.com/problems/sum-root-to-leaf-numbers/description/ Sum Root to Leaf Numbers You are given the root of a binary tree containing digits from 0 to 9 only. Each root-to-leaf path in the tree represents a number. For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123. Return the total sum of all root-to-leaf numbers. Test ...

Verify Preorder Serialization of a Binary Tree 4

Title: Verify Preorder Serialization of a Binary Tree Source: leetcode.com One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node’s value. If it is a null node, we record using a sentinel value such as #. _9_ / \ 3 2 / \ ...

Invert Binary Tree

Title: Invert Binary Tree Source: leetcode.com Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 12345      4   /   \  2     7 / \   / \1   3 6   9 to 4 / \ 7 2 / \ / \ 9 6 3 1 12345      4   /   \  7     ...

Maximum Depth of Binary Tree

Title: Maximum Depth of Binary Tree Source: leetcode.com Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Python solution Python ''' https://leetcode.com/problems/maximum-depth-of-binary-tree/ ''' # Definition for a binary tree node. # class TreeNode(object): # ...