class Solution {
public:
bool isSymmetric2(TreeNode* lr,TreeNode* rr) {
if(!lr&&!rr) return true;
else if(!lr&&rr) return false;
else if(lr&&!rr) return false;
else if(lr->val!=rr->val) return false;
else return isSymmetric2(lr->left,rr->right)&&isSymmetric2(lr->right,rr->left);
}
bool isSymmetric(TreeNode* root) {
if(!root) return true;
return isSymmetric2(root->left,root->right);
}
};
101. Symmetric Tree
最新推荐文章于 2019-04-15 20:39:00 发布