二:上码
/*** Definition for a binary tree node.* struct TreeNode {* int val;* TreeNode *left;* TreeNode *right;* TreeNode() : val(0), left(nullptr), right(nullptr) {}* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}* };*/
class Solution {
public:/**递归三部曲:1.确定递归函数的参数和返回值2.确定递归终止条件3.确定递归体 */void order(TreeNode* root,vector<int>&v) {if(root == NULL) return;order(root->left,v);v.push_back(root->val);order(root->right,v);} vector<int> inorderTraversal(TreeNode* root) {vector<int> ans;order(root,ans);return ans;}
};