knakul853

Untitled

Jul 22nd, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. /**
  2. knakul853
  3.  */
  4. class Solution {
  5. public:
  6.     vector<int>ans;
  7.     vector<int> inorderTraversal(TreeNode* root) {
  8.        
  9.        stack<TreeNode*> st;
  10.         vector<int>ans;
  11.         while(!st.empty() || root)
  12.         {
  13.            while( root != NULL)
  14.            {
  15.                st.push(root);
  16.                root = root->left;
  17.            }
  18.             root = st.top();st.pop();
  19.             ans.push_back(root->val);
  20.             root = root->right;
  21.          }
  22.         return ans;
  23.     }
  24. };
  25.  
  26. /**
  27.  
  28. class Solution {
  29. public:
  30.     vector<int>ans;
  31.     vector<int> inorderTraversal(TreeNode* root) {
  32.        
  33.         if( !root ) return {};
  34.        
  35.         inorderTraversal(root->left);
  36.         ans.push_back(root->val);
  37.         inorderTraversal(root->right);
  38.         return ans;
  39.        
  40.     }
  41. };
  42.  
  43. **/
Add Comment
Please, Sign In to add comment