diff --git a/5 May Vertical sum b/5 May Vertical sum new file mode 100644 index 00000000..d6218de9 --- /dev/null +++ b/5 May Vertical sum @@ -0,0 +1,61 @@ +class Solution{ + + public: + + int Nodes(Node* root){ + + if(root == NULL) return 0; + + return 1 + (Nodes(root->left) + Nodes(root->right)); + + } + + void fill(Node* root , vector& temp , int idx , int n){ + + //if(idx == -1 || idx >= n ) return; + + if(root == NULL) return; + + temp[idx] += root->data; + + fill(root->left,temp,idx-1,n); + + fill(root->right,temp,idx+1,n); + + } + + vector verticalSum(Node *root) { + + // add code here. + + int n = Nodes(root); + + vector temp(1e5,0); + + int idx = 50000; + + fill(root,temp,idx,n); + + vector result; + + bool flag = false; + + for(int i = 0 ; i < 1e5 ; i++){ + + //cout<