标签:tor tps traversal ini pre com ref efi push
/**
* 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;
}
};
LeetCode 94. Binary Tree Inorder Traversal
标签:tor tps traversal ini pre com ref efi push
原文地址:https://www.cnblogs.com/dacc123/p/12146278.html