topic:
2331Calculate the value of the Boolean binary tree
Thought:
For the currentroot,in the case ofleaf root(That is, the left node is empty),Then judge the current Boolean value(The leaf node must be Boolean instead of judging)。
Otherwise,Until traversing the leaf node,After seeing the left and right children of a sub -tree,Judge the current Valtype,Finally seekingValValue。
ifValNot the root node,butValChildren’s nodes as other trees return to the previous layer。
Code:
1 | class Solution: |
1 | type TreeNode struct { |