#include "iostream"
#include "vector"
using namespace std;
struct TreeNode
{
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution
{
public:
vector<int> ans;
vector<int> inorderTraversal(TreeNode *root)
{
if(root==NULL)
{
return ans;
}
if (root->left)
{
inorderTraversal(root->left);
}
ans.push_back(root->val);
if (root->right)
{
inorderTraversal(root->right);
}
return ans;
}
};
【Leetcode】94.二叉树的中序遍历C++(递归法)
猜你喜欢
转载自blog.csdn.net/weixin_44936889/article/details/104100473
今日推荐
周排行