二叉树的中序遍历,没啥好说的
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: vector<int>ans; void dfs(TreeNode *root){ if(!root) return ; dfs(root->left); ans.push_back(root->val); dfs(root->right); } vector<int> inorderTraversal(TreeNode *root) { dfs(root); return ans; } };