标签:etc tput def solution class ret init bin exist
/**
* 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:
vector<int> inorderTraversal(TreeNode* root) {
vector<int> midseq;
if(root == nullptr) return midseq;
stack<TreeNode *> s;
TreeNode *p=nullptr;
p=root;
while(!s.empty() || p != nullptr){
while(p != nullptr){ //left child is exist
s.push(p);
p=p->left;
}
if(!s.empty()){ //output left or root node to queue
p=s.top();
s.pop();
midseq.push_back(p->val);
p=p->right;
}
}
return midseq;
}
};
标签:etc tput def solution class ret init bin exist
原文地址:https://www.cnblogs.com/ymd01/p/15054001.html