题目


/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:

TreeNode* s[100005];
vector<int> inorderTraversal(TreeNode* root) {


TreeNode* term = root;
vector<int> ans;
if(root==NULL)
return ans;
int pos=0;

s[pos++] = term;

while(pos!=0)
{
TreeNode* temp = s[pos-1];
TreeNode* temp2 = s[pos-1];
if(temp->left!=NULL&&temp->left->val!=-99999999)
{
s[pos++]=temp->left;
continue;
}

ans.push_back(s[pos-1]->val);
pos--;
temp2->val=-99999999;

if(temp->right!=NULL&&temp->right->val!=-99999999)
{
s[pos++]=temp->right;
continue;
}



}

return ans;

}
};

相关文章:

  • 2022-12-23
  • 2021-12-02
  • 2022-02-28
猜你喜欢
  • 2021-10-08
  • 2021-12-01
  • 2022-01-23
  • 2021-05-16
  • 2021-07-01
相关资源
相似解决方案