Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Definition for a binary tree node.
- * struct TreeNode {
- * int val;
- * TreeNode *left;
- * TreeNode *right;
- * TreeNode() : val(0), left(nullptr), right(nullptr) {}
- * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
- * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
- * };
- */
- class Solution {
- public:
- bool helper(struct TreeNode* node1, struct TreeNode* node2) {
- if (!node1 && !node2)
- return 1;
- if (!node1 && node2 || node1 && !node2)
- return 0;
- if (node1->val != node2->val)
- return 0;
- bool call;
- call = helper(node1->left, node2->right);
- if (!call)
- return 0;
- call = helper(node1->right, node2->left);
- return call;
- }
- bool isSymmetric(TreeNode* root) {
- if(!root)
- {
- return 1;
- }
- return helper(root->left,root->right);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment