https://leetcode.com/problems/same-tree/
Source
string line;
FOR (i, 10) {
getline(cin, line);
if (line.length() > 2) {
break;
}
}
vstr vstrSplits = _SplitString(line, "[], \n", "=");
vstr vstrTree1;
vstr vstrTree2;
vstr* pvstrTree = nullptr;
bool isNode = false;
for (auto str : vstrSplits) {
if (("=" == str) && (nullptr == pvstrTree)) {
pvstrTree = &vstrTree1;
isNode = true;
continue;
}
if (nullptr != pvstrTree) {
if ("q" == str) {
isNode = false;
}
if (isNode) {
pvstrTree->push_back(str);
}
if ("=" == str) {
pvstrTree = &vstrTree2;
isNode = true;
}
}
}
m_root1 = BFSBuildBST(vstrTree1);
m_root2 = BFSBuildBST(vstrTree2);
bool isSameTree(TreeNode* p, TreeNode* q) {
if (nullptr == p && nullptr == q) return true;
if (nullptr == p || nullptr == q) return false;
if (p->val != q->val) return false;
const bool leftSame = isSameTree(p->left, q->left);
const bool rightSame = isSameTree(p->right, q->right);
return (leftSame && rightSame);
}