Skip to content

Instantly share code, notes, and snippets.

Created July 20, 2019 00:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
class Solution {
vector<int> inorderTraversal(TreeNode* root) {
vector<int> res;
stack<TreeNode*> st;
if(root == nullptr) return res;
//Maintain a variable for current value. For inorder traversal,
//we need to push left nodes to our stack, then add the value to res.
TreeNode* cur = root;
while(cur || !st.empty()){
if(cur!= nullptr){
cur = cur->left;
//We need to update cur. because currentlt it's nullptr
cur =;
cur = cur->right;
return res;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment