用递归实现中序遍历并存入vector中 void InOrder(TreeNode* root,vector<int>& a) { int i=0; if(root) { InOrder(root->left,a); a.push_back(root->val); InOrder(root->right,a); } } class Solution { public: vector<int> inorderTraversal(TreeNode* root) { vector<int> a; InOrder(root,a); return a; } };