LeetCode 94. Binary Tree Inorder Traversal
Posted Shendu.cc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode 94. Binary Tree Inorder Traversal相关的知识,希望对你有一定的参考价值。
/**
* 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的主要内容,如果未能解决你的问题,请参考以下文章
[leetcode-94-Binary Tree Inorder Traversal]
[LeetCode]94.Binary Tree Inorder Traversal
leetcode 94. Binary Tree Inorder Traversal
LeetCode94 Binary Tree Inorder Traversal