原题
思路: Dfs.
class Solution {
public:
vector<int> inorderTraversal(TreeNode *root) {
vector<int> vec;
dfs(root, vec);
return vec;
}
void dfs(TreeNode *root, vector<int> &vec) {
if (root) {
dfs(root->left, vec);
vec.push_back(root->val);
dfs(root->right, vec);
}
}
};
转载于:https://www.cnblogs.com/ruoh3kou/p/9893442.html