题解 | #二叉树的中序遍历#
二叉树的中序遍历
https://www.nowcoder.com/practice/0bf071c135e64ee2a027783b80bf781d
class Solution { public: vector<int> inorderTraversal(TreeNode* root) { // write code here vector<int> ret; if(!root) return ret; TreeNode* cur=root; stack<TreeNode*> s; s.push(root); while(!s.empty()) { while(cur->left) { s.push(cur->left); cur=cur->left; } TreeNode* temp = s.top(); s.pop(); ret.push_back(temp->val); if(temp->right){ cur=temp->right; s.push(cur); } } return ret; } };