leetcode-华为专题-94. 二叉树的中序遍历
/** * 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: vector<int> res; vector<int> inorderTraversal(TreeNode* root) { if(root==NULL) return res; inorder(root); return res; } void inorder(TreeNode* root){ if(root==NULL) return; if(root->left) inorder(root->left); res.push_back(root->val); if(root->right) inorder(root->right); } };