原题地址(中等)
这题竟然是中等难度,有点侮辱智商。。。
入门级的二叉树算法。
class Solution {
public:
vector<int> v;
vector<int> inorderTraversal(TreeNode* root) {
dfs(root);
return v;
}
void dfs(TreeNode* root){
if(!root) return;
dfs(root->left);
v.push_back(root->val);
dfs(root->right);
}
};
上一篇:二叉树