LeetCode 94.二叉树的中序遍历
题目链接: https://leetcode-cn.com/problems/binary-tree-inorder-traversal/ 题目描述:给定一个二叉树,返回它的 中序 遍历。 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 思路:简单的中序遍历~ 代码: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: vector<int> v; void inorder(TreeNode* root){ if(root == NULL) return; inorder(root -> left); v.push_back(root -> val); inorder(root -> right); } vector<int> inorderTraversal(TreeNode* root) { inorder(root); return v; } }; 来源: CSDN 作者: Xinstein666 链接