category-wise-problems

contains category wise problems(data structures, competitive) of popular platforms.

View the Project on GitHub mayankdutta/category-wise-problems

94. Binary Tree Inorder Traversal

Recursive ```cpp class Solution { public: vector inorderTraversal(TreeNode* root) { vector ans; auto inOrder = [&](const auto& self, TreeNode* head) -> void { if (head == nullptr) return; self(self, head -> left); ans.push_back(head -> val); self(self, head -> right); }; inOrder(inOrder, root); return ans; } }; ``` </details>
Iterative ```cpp class Solution { public: vector inorderTraversal(TreeNode* root) { vector ans; stack<TreeNode*> st; while (root != nullptr or !st.empty()) { while (root != nullptr) { st.push(root); root = root -> left; } root = st.top(); st.pop(); ans.push_back(root -> val); root = root -> right; } return ans; } }; ``` </details>