vector<int> ans; void dfs(TreeNode* now){ if (now==nullptr) return ; dfs(now->left); ans.push_back(now->val); dfs(now->right); } class Solution { public: vector<int> inorderTraversal(TreeNode* root) { ans.clear(); dfs(root); return ans; } };
原文:https://www.cnblogs.com/wegret/p/14897657.html