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>