42. Trapping Rain Water class Solution { public: ?int trap(vector<int>& height) { ? ? if (height.empty()) return 0; ? ? int n = height.size(), left = 0, right = n - 1, res = 0, maxleft = height[left], maxright = height[right]; ? ? while (left < right) { ? ? ? ? if (height[left] <= height[right]) { ? ? ? ? ? ? maxleft = max(maxleft, height[left]); ? ? ? ? ? ? res += maxleft - height[left]; ? ? ? ? ? ? ++left; ? ? ? ? } else { ? ? ? ? ? ? maxright = max(maxright, height[right]); ? ? ? ? ? ? res += maxright - height[right]; ? ? ? ? ? ? --right; ? ? ? ? } ? ? } ? ? return res; } };
AMAN KUMAR的动态
最相关的动态
-
42. Trapping Rain Water Note: Use three pointers! First find the highest index in the middle, Then Traverse the heights from left until the highest index and the water will be leftMax - height[i] and if the current height > leftMax just updated it then do the same thing from the right. TC: O(n) as we are traversing the list twice SC: O(1) as we are using pointers only
要查看或添加评论,请登录
-
-
Crawl space encapsulation helps control moisture levels, preventing the growth of mold and mildew, which can reduce home air quality. https://lnkd.in/gxRxu4iv
要查看或添加评论,请登录
-
Great video to help understand thermal load effects on concrete.
Can the sun move mountains? No, but it can move concrete girders. Watch this timelapse video of vertical and horizontal movements caused by thermal gradients from the sun on an unrestrained girder. Cool to watch it return to its starting point in the 24 hour cycle.
要查看或添加评论,请登录
-
One of the most interesting aspects of our industry is how the components move, grow and shrink due to temperature changes. Buildings and bridges are both built to move so they don’t break themselves.
Can the sun move mountains? No, but it can move concrete girders. Watch this timelapse video of vertical and horizontal movements caused by thermal gradients from the sun on an unrestrained girder. Cool to watch it return to its starting point in the 24 hour cycle.
要查看或添加评论,请登录
-
Today's Question? Trapping Rain Water : Description : ??Given?'n'?non-negative integers representing an elevation map where the width of each bar is?1, compute how much water it can trap after rain. ??Approach: ??Finding the left maximum & right maximum array of the elevation graph & calculate the sum using the formula is - ? sum = min(Left max array , Right max array) - Hight of the elevation graph.
要查看或添加评论,请登录
-
-
Crawl space encapsulation helps control moisture levels, preventing the growth of mold and mildew, which can reduce home air quality. https://lnkd.in/gSmjKhQs
要查看或添加评论,请登录
-
High winds can do more than just mess with the structural integrity of umbrellas. They can damage your roof. The good news? It’s avoidable – as this post will discuss. ?? https://bit.ly/3E4fJuA
要查看或添加评论,请登录
-
Crawl spaces are prone to moisture buildup, which can lead to mold growth. An inspection can identify moisture and mold issues. https://lnkd.in/eXBK6pKK
要查看或添加评论,请登录
-
Crawl spaces are prone to moisture buildup, which can lead to mold growth. An inspection can identify moisture and mold issues. https://lnkd.in/gSmjKhQs
要查看或添加评论,请登录