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 ce1099d + a1a4023 commit a5e08f3Copy full SHA for a5e08f3
Trees/Maximum width of tree
@@ -0,0 +1,35 @@
1
+class Solution {
2
+ public:
3
+ // Function to get the maximum width of a binary tree.
4
+ int getMaxWidth(Node* root)
5
+ {
6
+ if(root==NULL)
7
8
+ return 0;
9
+ }
10
+ queue<Node*>q;
11
+ q.push(root);
12
+ int res=0;
13
+ while(q.empty()==false)
14
15
+ int curr=q.size();
16
+ res=max(curr,res);
17
+ for(int i=0;i<curr;i++)
18
19
+ Node*curr=q.front();
20
+ q.pop();
21
+
22
+ if(curr->left!=NULL)
23
24
+ q.push(curr->left);
25
26
+ if(curr->right!=NULL)
27
28
+ q.push(curr->right);
29
30
31
32
+ return res;
33
+ // Your code here
34
35
+};
0 commit comments