diff --git a/Leetcode problems/94-Binary-Tree-Inorder-Traversal b/Leetcode problems/94-Binary-Tree-Inorder-Traversal new file mode 100644 index 00000000..0cebbcb3 --- /dev/null +++ b/Leetcode problems/94-Binary-Tree-Inorder-Traversal @@ -0,0 +1,33 @@ +/** + * 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 inorder(TreeNode* root, vector &v){ + if(root->left!=NULL){ + inorder(root->left, v); + } + v.push_back(root->val); + if(root->right!=NULL){ + inorder(root->right, v); + } + } + + + vector inorderTraversal(TreeNode* root) { + vector v; + if(root==NULL){ + return v; + } + inorder(root,v); + return v; + } +};