LeetCode94. 二叉树的中序遍历

题目

分析

代码

 1 class Solution {
 2 public:
 3     void dfs(TreeNode* root,vector<int>&res){
 4         if(root == NULL) return;
 5 
 6         dfs(root->left,res);
 7         res.push_back(root->val);//对根的处理
 8         dfs(root->right,res);
 9     }
10     vector<int> inorderTraversal(TreeNode* root) {
11         vector<int>res;
12         dfs(root,res);
13         return res;
14     }
15 };

 

原文地址:https://www.cnblogs.com/fresh-coder/p/14433072.html