Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zhangxiaomu01
Created July 20, 2019 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangxiaomu01/19bdeb6bec3cf8fc92a288745b4f0563 to your computer and use it in GitHub Desktop.
Save zhangxiaomu01/19bdeb6bec3cf8fc92a288745b4f0563 to your computer and use it in GitHub Desktop.
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