Skip to content

Commit b7f0959

Browse files
authored
Create main.cpp
1 parent 5464406 commit b7f0959

File tree

1 file changed

+19
-0
lines changed
  • 17 - Binary Tree Data Structure Problems/20 - Left View of Binary Tree

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
private:
3+
void solve(Node* root, vector<int> &ans, int level){
4+
if(root == NULL) return;
5+
6+
if(level == ans.size()) ans.push_back(root -> data);
7+
8+
solve(root -> left, ans, level+1);
9+
solve(root -> right, ans, level+1);
10+
}
11+
public:
12+
vector<int> leftView(Node *root) {
13+
vector<int> ans;
14+
15+
solve(root, ans, 0);
16+
17+
return ans;
18+
}
19+
};

0 commit comments

Comments
 (0)