TrappingRainWater

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 raining.

ํ•„์š”ํ•œ ์ž๋ฃŒ๊ตฌ์กฐ : ์ •์ˆ˜ํ˜• ๋ฐฐ์—ด 2๊ฐœ (left[ ], right[ ])

์•Œ๊ณ ๋ฆฌ์ฆ˜ 1. ์™ผ์ชฝ ๋ฒฝ(left)๊ณผ ์˜ค๋ฅธ์ชฝ ๋ฒฝ(right)์„ ๊ตฌํ•œ๋‹ค. - ์ •์ˆ˜ํ˜• ๋ฐฐ์—ด left[ ], right[ ] ์ƒ์„ฑ. 2. left์™€ right ์ค‘ ์ž‘์€ ๊ฐ’์„ ๊ตฌํ•œ๋‹ค. ๋‘˜ ์ค‘ ์ž‘์€ ๊ฐ’์˜ ๋†’์ด๋งŒํผ ๋ฌผ์ด ์ฐจ๊ธฐ ๋•Œ๋ฌธ! - Math.min(l,r) 3. ์ž์‹ ์˜ ๋ฒฝ ๋†’์ด๋งŒํผ ๋บ€๋‹ค. => result += Math.min(left[i],right[i]) - height[i]

์•Œ๊ณ ๋ฆฌ์ฆ˜์„ java์–ธ์–ด๋กœ ๊ตฌํ˜„

Last updated

Was this helpful?