Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Solution {
private:
void dfs(vector<int>& res, TreeNode* root){
if(root == nullptr) return;
dfs(res, root->left);
res.push_back(root->val);
dfs(res, root->right);
}
public:
vector<int> inorderTraversal(TreeNode* root) {
vector<int> res;
dfs(res, root);
return res;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment