迭代是不可能迭代的
1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */ 10 class Solution { 11 public: 12 bool flag = true; //判断标志 13 bool isSymmetric(TreeNode* root) { 14 if (!root) return 1; 15 dfs(root->left, root->right); 16 return flag; 17 } 18 void dfs(TreeNode* L, TreeNode* R) { 19 if (!flag || !L && !R) return; //剪枝 20 else if (!L || !R || L->val != R->val) { //判断不对称 21 flag = false; 22 return; 23 } 24 dfs(L->left, R->right); //对称搜索比较 25 dfs(L->right, R->left); 26 } 27 };