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.
1 parent c69cb76 commit e9831c2Copy full SHA for e9831c2
Maximum width of tree.cpp
@@ -0,0 +1,23 @@
1
+int getMaxWidth(Node* root){
2
+ if(root==NULL){
3
+ return 0;
4
+ }
5
+ priority_queue<int>pq;
6
+ queue<Node *>Q;
7
+ Q.push(root);
8
+ while(!Q.empty()){
9
+ int size=Q.size();
10
+ pq.push(size);
11
+ for(int i=0;i<size;i++){
12
+ Node * top=Q.front();
13
+ Q.pop();
14
+ if(top->left){
15
+ Q.push(top->left);
16
17
+ if(top->right){
18
+ Q.push(top->right);
19
20
21
22
+ return pq.top();
23
+}
0 commit comments