Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- knakul853
- */
- class Solution {
- public:
- vector<int>ans;
- vector<int> inorderTraversal(TreeNode* root) {
- stack<TreeNode*> st;
- vector<int>ans;
- while(!st.empty() || root)
- {
- while( root != NULL)
- {
- st.push(root);
- root = root->left;
- }
- root = st.top();st.pop();
- ans.push_back(root->val);
- root = root->right;
- }
- return ans;
- }
- };
- /**
- class Solution {
- public:
- vector<int>ans;
- vector<int> inorderTraversal(TreeNode* root) {
- if( !root ) return {};
- inorderTraversal(root->left);
- ans.push_back(root->val);
- inorderTraversal(root->right);
- return ans;
- }
- };
- **/
Add Comment
Please, Sign In to add comment