public boolean isSameTree2(TreeNode p, TreeNode q){
    Stack<TreeNode> pstack = new Stack<TreeNode>();
    Stack<TreeNode> qstack = new Stack<TreeNode>();
    pstack.push(p);
    qstack.push(q);
    
    while(!pstack.isEmpty() && !qstack.isEmpty()){
        p = pstack.pop();
        q = qstack.pop();
        if (p != null && q != null && p.val == q.val){
            pstack.push(p.right);
            pstack.push(p.left);
            qstack.push(q.right);
            qstack.push(q.left);
        } else if (p == null && q == null)
            continue;
        else
            return false;
    }
    if (!pstack.isEmpty() || !qstack.isEmpty())
        return false;
    
    return true;
  }