[Daily OJ——101. Symmetric Binary Tree]

1.Topic: 101. Symmetric Binary Tree

Insert image description here

2.Solution

2.1. Algorithm explanation

1. This question is to determine whether the binary tree is symmetrical. The key is that the left subtree is equal to the right subtree, and the given interface has only one parameter, so an interface must be implemented to determine whether the left and right subtrees are equal. , and then convert to whether the binary tree is symmetric.
2. If both the left and right subtrees of the binary tree are empty, it is symmetrical. If only one of the subtrees is empty, it is asymmetrical. It is also asymmetrical if the values ​​are not equal. Then in the recursive judgment Whether the left and right subtrees are symmetrical is ultimately used to determine whether the binary tree is symmetrical.

2.2. Code implementation

Insert image description here

2.3.Submission through display

Insert image description here

Guess you like

Origin blog.csdn.net/qq_73900397/article/details/134779275