链接
力扣(LeetCode)官网 - 全球极客挚爱的技术成长平台
思路 :
采取递归的方式,中序遍历的顺序是左中右,然后模拟即可;
代码
class Solution {
public:void transfer(TreeNode* cur , vector<int>& vec){if(cur == nullptr) return;transfer(cur->left,vec);vec.push_back(cur->val);transfer(cur->right,vec);}vector<int> inorderTraversal(TreeNode* root) {vector<int> res;transfer(root,res);return res;}
};