How to solve the problem of picking up Rain Water by Java
This article mainly introduces "how to solve the problem of connecting Rain Water with Java". In daily operation, I believe many people have doubts about how to solve the problem of connecting Rain Water with Java. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "how to solve the problem of connecting Rain Water with Java". Next, please follow the editor to study!
Int trap (vector& height) {int ans = 0, current = 0; stack st; while (current)
< height.size()) { while (!st.empty() && height[current] >Height [st.top ()]) {int top = st.top (); st.pop (); if (st.empty ()) break; int distance = current-st.top ()-1; int bounded_height = min (height [current], height [st.top ()])-height [top]; ans + = distance * bounded_height } st.push (current++);} return ans;} at this point, the study on "how to solve the problem of picking up Rain Water by Java" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!