Trapping Rain Water

Source: Internet
Author: User

Feeling and

Container with most water

Very much like, here is a question, if let the ball biggest pit, how to do?

and candy the problem, it seems that the double sweep series

Ref http://fisherlei.blogspot.com/2013/01/leetcode-trapping-rain-water.html Double Sweep

 Public classSolution { Public intTrapint[] A) {if(a==NULL|| A.LENGTH&LT;3)return0; intres=0, curv = 0, max=a[0]; int[] ML =New int[A.length]; int[] MR =New int[A.length];  for(intI=1; i<a.length-1; i++) {Ml[i]=Max; Max=Math.max (A[i],max); } Max= A[a.length-1];  for(intJ=a.length-2; j>=0; j--) {Mr[j]=Max; Max=Math.max (A[j], max); CURV= Math.min (Ml[j], mr[j])-A[j]; if(curv>0) Res+=curv; }                returnRes; }}

Trapping Rain Water

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.