标签:== iostream 遍历 turn ace har int hello ica
考察二叉树的遍历。判断前序遍历,与新增的前->右->左遍历结果是否一致。
#include <iostream>
#include <algorithm>
using namespace std;
// 定义二叉树
struct TreeNode{
int val;
struct TreeNode* left;
struct TreeNode* right;
TreeNode(int val):val(val),left(nullptr),right(nullptr){}
};
bool isSymmetrical(TreeNode* pRoot1, TreeNode* pRoot2){
if(pRoot1 == nullptr && pRoot2 == nullptr)
return true;
if(pRoot1 == nullptr || pRoot2 == nullptr)
return false;
if(pRoot1->val != pRoot2->val)
return false;
return isSymmetrical(pRoot1->left, pRoot2->right) && isSymmetrical(pRoot1->right, pRoot2->left);
}
bool isSymmetrical(TreeNode* pRoot){
return isSymmetrical(pRoot, pRoot);
}
int main()
{
char *p = "hello";
// p[0] = ‘H‘;
cout<<p<<endl;
return 0;
}
标签:== iostream 遍历 turn ace har int hello ica
原文地址:https://www.cnblogs.com/flyingrun/p/13378429.html