今天毫无状态,唉
/*
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};
*/
class Solution {
public:
bool isSymmetrical(TreeNode* pRoot) {
if (pRoot == nullptr) {
return true;
}
std::queue<TreeNode *> queue_1, queue_2;
queue_1.push(pRoot->left);
queue_2.push(pRoot->right);
while (!queue_1.empty() && !queue_2.empty()) {
TreeNode *ptr_1 = queue_1.front();
TreeNode *ptr_2 = queue_2.front();
queue_1.pop();
queue_2.pop();
if (ptr_1 == nullptr && ptr_2 == nullptr) {
continue;
}
if (ptr_1 == nullptr || ptr_2 == nullptr || ptr_1->val != ptr_2->val) {
return false;
}
queue_1.push(ptr_1->left);
queue_1.push(ptr_1->right);
queue_2.push(ptr_2->right);
queue_2.push(ptr_2->left);
}
return true;
}
};