We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents fe2d61a + 0bb7978 commit c1f06a8Copy full SHA for c1f06a8
6 May Left View of Binary Tree
@@ -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