Leetcode Largest Rectangle in Histogram

Source: Internet
Author: User

Leetcode Largest Rectangle in Histogram
This question is definitely a challenge. I had a lot of worship and thought for an hour. I went online for a night. After learning, we will share the following records. Specify a histogram to find the maximum area of the rectangle. Example: Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. above is a histogram where width of each bar is 1, given height = [,]. the largest rectangle is shown in the shaded area, which has area = 10 unit. for example, Given height = [2, 1, 5, 6, 2, 3], return 10. the intuitive idea is that each box is the highest, and the current box can be found on both sides of the left and right. The length of the span. Record the maximum value. This is nparty's. I won't even try it. Because it definitely times out. Is there any better. Yes. Pruning: although the worst side is n, it saves a lot of computation, and the AC can select the right boundary for a Pruning (Pruning ). When height [k]> = height [k-1], no matter what the left boundary is, selecting height [k] is always larger than selecting height [k-1. Therefore, when selecting the right boundary, first find a k of height [k]

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.