本文共 328 字,大约阅读时间需要 1 分钟。
题目:求二叉树的中序遍历
思路:直接中序遍历。
class Solution {public: vector v; void inorder(TreeNode *root){ if(!root) return ; inorder(root->left); v.push_back(root->val); inorder(root->right); } vector inorderTraversal(TreeNode* root) { inorder(root); return v; }};
转载地址:http://cirai.baihongyu.com/