Untitled
unknown
plain_text
a year ago
764 B
3
Indexable
/** * 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: void actualTraversal(TreeNode* root, vector<int> &ans){ if(root == NULL){ return; } actualTraversal(root->left, ans); ans.push_back(root->val); actualTraversal(root->right, ans); } vector<int> inorderTraversal(TreeNode* root) { vector<int> ans; actualTraversal(root, ans); return ans; } };
Editor is loading...