-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
/**
* 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> ans(0);
stack<TreeNode*> st;
while(root != NULL || !st.empty()) {
while(root != NULL) {
st.push(root);
root = root->left;
}
root = st.top();
st.pop();
ans.push_back(root->val);
root = root->right;
}
return ans;
}
};
Metadata
Metadata
Assignees
Labels
No labels