![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/025cfc8b486d758f35ca1d49268404df.png)
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
void dfs(TreeNode* root, vector<int>& res) {
if (nullptr == root) return;
dfs(root->left, res);
res.push_back(root->val);
dfs(root->right, res);
return;
}
vector<int> inorderTraversal(TreeNode* root) {
vector<int> res;
dfs(root, res);
return res;
}
};