Skip to content

Commit baf6968

Browse files
author
cpppy
authored
Create 94_Binary_Tree_Inorder_Traversal.cc
https://leetcode.com/problems/binary-tree-inorder-traversal/
1 parent 6ceb0db commit baf6968

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

94_Binary_Tree_Inorder_Traversal.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
8+
* };
9+
*/
10+
class Solution {
11+
public:
12+
vector<int> inorderTraversal(TreeNode* root) {
13+
vector<int> res;
14+
if(root==NULL) return res;
15+
inorder(root,res);
16+
return res;
17+
18+
}
19+
void inorder(TreeNode* root,vector<int> &res){
20+
if(root==NULL) return;
21+
inorder(root->left,res);
22+
res.push_back(root->val);
23+
inorder(root->right,res);
24+
}
25+
};

0 commit comments

Comments
 (0)