Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c1f06a8

Browse filesBrowse files
authored
Create 6 May Left View of Binary Tree (#788)
2 parents fe2d61a + 0bb7978 commit c1f06a8
Copy full SHA for c1f06a8

File tree

1 file changed

+29
-0
lines changed
Filter options

1 file changed

+29
-0
lines changed

‎6 May Left View of Binary Tree

Copy file name to clipboard
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
public:
3+
vector<int> leftView(Node *root) {
4+
// code here
5+
vector<int> result;
6+
if (!root) return result;
7+
8+
queue<Node*>q;
9+
q.push(root);
10+
11+
while(!q.empty()){
12+
13+
int n=q.size();
14+
Node* curr = q.front();
15+
result.push_back(curr->data);
16+
17+
while(n--){
18+
Node* x = q.front();
19+
q.pop();
20+
if(x->left)
21+
q.push(x->left);
22+
if(x->right)
23+
q.push(x->right);
24+
}
25+
}
26+
return result;
27+
}
28+
};
29+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.