Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
404reese authored Jun 2, 2024
1 parent f6473fd commit 6af2f57
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Day25_LeetCode42.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution {
public int trap(int[] height) {
int n = height.length ;
int[] leftMax = new int[n];
leftMax[0]=height[0];

for(int i=1;i<n;i++){
leftMax[i] = Math.max(leftMax[i-1],height[i]);
}

int[] rightMax = new int[n];
rightMax[n-1]=height[n-1];
for(int i=n-2;i>=0;i--){
rightMax[i] = Math.max(rightMax[i+1],height[i]);
}

int ans = 0 ;
for(int i=0;i<n;i++){
ans += Math.min(leftMax[i],rightMax[i])-height[i];
}

return ans ;
}
}
7 changes: 7 additions & 0 deletions Day25_LeetCode42.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**Day 25: LeetCode 42 [Trapping Rain water]**

**Problem Description:**


**Link to LeetCode Problem:**
https://leetcode.com/problems/trapping-rain-water/description/

0 comments on commit 6af2f57

Please sign in to comment.