/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isSymmetric(TreeNode *root) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if (!root) return true;
return isEqual(root->left, root->right);
}
bool isEqual(TreeNode* n1, TreeNode* n2)
{
if (n1 && n2)
{
if (n1->val == n2->val)
return isEqual(n1->left, n2->right) && isEqual(n1->right, n2->left);
else
return false;
}
else if (!n1 && !n2)
return true;
else
return false;
}
};
[Leetcode] Symmetric Tree
最新推荐文章于 2019-05-29 13:59:21 发布