<p>Given the roots of two binary trees <code>p</code> and <code>q</code>, write a function to check if they are the same or not.</p>

<p>Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/20/ex1.jpg" style="width: 622px; height: 182px;" />
<pre>
<strong>Input:</strong> p = [1,2,3], q = [1,2,3]
<strong>Output:</strong> true
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/20/ex2.jpg" style="width: 382px; height: 182px;" />
<pre>
<strong>Input:</strong> p = [1,2], q = [1,null,2]
<strong>Output:</strong> false
</pre>

<p><strong class="example">Example 3:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/20/ex3.jpg" style="width: 622px; height: 182px;" />
<pre>
<strong>Input:</strong> p = [1,2,1], q = [1,1,2]
<strong>Output:</strong> false
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li>The number of nodes in both trees is in the range <code>[0, 100]</code>.</li>
	<li><code>-10<sup>4</sup> &lt;= Node.val &lt;= 10<sup>4</sup></code></li>
</ul>

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    bool isSameTree(TreeNode* p, TreeNode* q) {
        if (!p && !q) {
            return true;
        } else if (p == NULL && q != NULL){
            return false;
        } else if (p != NULL && q == NULL){
            return false;
        }
        stack<TreeNode*> stack1;
        stack<TreeNode*> stack2;
        stack1.push(p);
        stack2.push(q);
        TreeNode* temp = new TreeNode();
        while(!stack1.empty()) {
            if (p->left == NULL && q->left){
            return false;
        } else if (p->left && q == NULL){
            return false;
        } else if (p->right == NULL && q->right){
            return false;
        } else if (p->right && q == NULL){
            return false;
        }
            if(p->left && q->left){
                cout << "huh" << endl;
                stack1.push(p);
                stack2.push(q);
                temp = p->left;
                p->left = NULL;
                p = temp;
                temp = q->left;
                q->left = NULL;
                q = temp;
            } else if (p->right && q->right){
                cout << "huhr" << endl;
                stack1.push(p);
                stack2.push(q);
                temp = p->right;
                p->right = NULL;
                p = temp;
                temp = q->right;
                q->right = NULL;
                q = temp;
            } else if (!p->right && !q->right) {
                
                if (p->val != q->val) {
                    cout << "huhe1" << endl;
                    return false;
                }
                if(stack1.empty() && stack2.empty()){
                    break;
                } else if (stack1.empty() != stack2.empty()) {
                    cout << "huhe" << endl;
                    return false;
                }
                p = stack1.top();
                q = stack2.top();
                stack1.pop();
                stack2.pop();
            } else {
                cout << "ff" << endl;
                return false;
            }
        }
        return true;
    }
};
11300