Video Explanation
Solution Video\n\nhttps://youtu.be/WTbLeCP8rwM\n\n### \u2B50\uFE0F\u2B50\uFE0F Don\'t forget to subscribe to my channel! \u2B50\uFE0F\u2B50\uFE0F\n\n\u25A0 Subs
# Solution Video\n\nhttps://youtu.be/WTbLeCP8rwM\n\n### \u2B50\uFE0F\u2B50\uFE0F Don\'t forget to subscribe to my channel! \u2B50\uFE0F\u2B50\uFE0F\n\n**\u25A0 Subscribe URL**\nhttp://www.youtube.com/channel/UC9RMNwYTL3SXCP6ShLWVFww?sub_confirmation=1\n\nSubscribers: 6,001\nThank you for your support!\n\n---\n\nhttps://youtu.be/bU_dXCOWHls\n\n---\n\n```python []\nclass Solution:\n    def largestRectangleArea(self, heights: List[int]) -> int:\n        stack = [-1]\n        max_area = 0\n\n        for i in range(len(heights)):\n            while stack[-1] != -1 and heights[i] <= heights[stack[-1]]:\n                height = heights[stack.pop()]\n                width = i - stack[-1] - 1\n                max_area = max(max_area, height * width)\n            stack.append(i)\n        \n        while stack[-1] != -1:\n            height = heights[stack.pop()]\n            width = len(heights) - stack[-1] - 1\n            max_area = max(max_area, height * width)\n        \n        return max_area\n```\n```javascript []\n/**\n * @param {number[]} heights\n * @return {number}\n */\nvar largestRectangleArea = function(heights) {\n        const stack = [-1];\n        let max_area = 0;\n\n        for (let i = 0; i < heights.length; i++) {\n            while (stack[stack.length - 1] !== -1 && heights[i] <= heights[stack[stack.length - 1]]) {\n                const height = heights[stack.pop()];\n                const width = i - stack[stack.length - 1] - 1;\n                max_area = Math.max(max_area, height * width);\n            }\n            stack.push(i);\n        }\n\n        while (stack[stack.length - 1] !== -1) {\n            const height = heights[stack.pop()];\n            const width = heights.length - stack[stack.length - 1] - 1;\n            max_area = Math.max(max_area, height * width);\n        }\n\n        return max_area;\n};\n```\n```java []\nimport java.util.Stack;\n\nclass Solution {\n    public int largestRectangleArea(int[] heights) {\n        Stack<Integer> stack = new Stack<>();\n        stack.push(-1);\n        int maxArea = 0;\n\n        for (int i = 0; i < heights.length; i++) {\n            while (stack.peek() != -1 && heights[i] <= heights[stack.peek()]) {\n                int height = heights[stack.pop()];\n                int width = i - stack.peek() - 1;\n                maxArea = Math.max(maxArea, height * width);\n            }\n            stack.push(i);\n        }\n\n        while (stack.peek() != -1) {\n            int height = heights[stack.pop()];\n            int width = heights.length - stack.peek() - 1;\n            maxArea = Math.max(maxArea, height * width);\n        }\n\n        return maxArea;\n    }\n}\n```\n```C++ []\nclass Solution {\npublic:\n    int largestRectangleArea(vector<int>& heights) {\n        stack<int> stack;\n        stack.push(-1);\n        int max_area = 0;\n\n        for (int i = 0; i < heights.size(); i++) {\n            while (stack.top() != -1 && heights[i] <= heights[stack.top()]) {\n                int height = heights[stack.top()];\n                stack.pop();\n                int width = i - stack.top() - 1;\n                max_area = max(max_area, height * width);\n            }\n            stack.push(i);\n        }\n\n        while (stack.top() != -1) {\n            int height = heights[stack.top()];\n            stack.pop();\n            int width = heights.size() - stack.top() - 1;\n            max_area = max(max_area, height * width);\n        }\n\n        return max_area;        \n    }\n};\n```\n\n---\n\nThank you for reading my post.\n\n##### \u2B50\uFE0F Subscribe URL\nhttp://www.youtube.com/channel/UC9RMNwYTL3SXCP6ShLWVFww?sub_confirmation=1\n\n##### \u2B50\uFE0F Twitter\nhttps://twitter.com/CodingNinjaAZ\n\n##### \u2B50\uFE0F My recent video\n#33 Search in Rotated Sorted Array\n\nhttps://youtu.be/dO9OZJP_Hm8\n
['C++', 'Java', 'Python3', 'JavaScript']