标签:iss col nbsp nod for struct init ++ ret
给定一个二叉树,检查它是否是镜像对称的。
C++
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: bool isSymmetric(TreeNode* root) { if(root == NULL) return true; return dfs(root->left, root->right); } bool dfs(TreeNode *lt, TreeNode *rt) { if(lt == NULL && rt == NULL) return true; if(lt && rt && lt->val == rt->val) return dfs(lt->left, rt->right) && dfs(lt->right, rt->left); return false; } };
标签:iss col nbsp nod for struct init ++ ret
原文地址:https://www.cnblogs.com/xumaomao/p/11354585.html