Skip to content

Commit

Permalink
Merge pull request #40 from Manishak798/Manishak798-patch-36
Browse files Browse the repository at this point in the history
Create tappingrainwater.cpp
  • Loading branch information
Manishak798 authored Nov 21, 2024
2 parents e99b6ef + 1829f74 commit 6efaf53
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions OOPS/tappingrainwater.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Solution {
public:
int trap(vector<int>& height) {
int lMax = 0;
int rMax = 0;
int total = 0;
int left = 0;
int right = height.size()-1;
while(left < right){
if(height[left] <= height[right]){
if(lMax > height[left]){
total += lMax-height[left];
}else{
lMax = height[left];
}
left = left+1;
}
else{
if(rMax > height[right]){
total += rMax - height[right];
}else{
rMax = height[right];
}
right = right - 1;
}
}
return total;
}
};

0 comments on commit 6efaf53

Please sign in to comment.