------
## 最终结论
```python
def largestRectangleArea(heights):
    stack = []
    max_area = 0
    heights.append(0)  # Append a sentinel value to pop all remaining bars

    for i in range(len(heights)):
        while stack and heights[stack[-1]] > heights[i]:
            h = heights[stack.pop()]
            w = i if not stack else i - stack[-1] - 1
            max_area = max(max_area, h * w)
        stack.append(i)

    return max_area

# Example usage
heights = [2, 1, 5, 6, 2, 3]
print(largestRectangleArea(heights))  # Output: 10
```