树:
- 求二叉树的高度(Maximum Depth of Binary Tree)
// 时间复杂度O(n),空间复杂度O(logn)
class Solution {
public:
int maxDepth(TreeNode *root) {
if (root == nullptr) return 0;
return max(maxDepth(root->left), maxDepth(root->right)) + 1;
}
};
- 判断二叉树是否对称(Symmetric Tree)