Binary Tree Inorder Traversal LeetCode solution in C++
1class Solution {2public:3vector<int> inorderTraversal(TreeNode *root) {4vector<int> nodes;5stack<TreeNode *> todo;6while (root || !todo.empty()) {7while (root) {8todo.push(root);9root = root->left;10}11root = todo.top();12todo.pop();13nodes.push_back(root->val);14root = root->right;15}16return nodes;17}18};