Title: #85 - Maximal Rectangle - LeetCode JavaScript Solutions
Open Graph Title: #85 - Maximal Rectangle - LeetCode JavaScript Solutions
X Title: #85 - Maximal Rectangle - LeetCode JavaScript Solutions
Description: Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area...
Open Graph Description: Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area...
X Description: Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/maximal-rectangle
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/maximal-rectangle","name":"#85 - Maximal Rectangle - LeetCode JavaScript Solutions","description":"Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {character[][]} matrix\n * @return {number}\n */\nvar maximalRectangle = function(matrix) {\n if (!matrix?.length) return 0;\n let maxArea = 0;\n\n for (let i = 0; i < matrix.length; i++) {\n for (let j = 0; j < matrix[0].length; j++) {\n if (matrix[i][j] === '1') {\n let minWidth = matrix[0].length;\n\n for (let k = i; k < matrix.length && matrix[k][j] === '1'; k++) {\n let width = 0;\n\n while (width < minWidth && j + width < matrix[0].length && matrix[k][j + width] === '1') {\n width++;\n }\n\n minWidth = Math.min(minWidth, width);\n maxArea = Math.max(maxArea, minWidth * (k - i + 1));\n }\n }\n }\n }\n\n return maxArea;\n};","keywords":"LeetCode 85, #85 - Maximal Rectangle, Hard, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/maximal-rectangle |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/maximal-rectangle/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0085-maximal-rectangle.js |
| Array | https://leetcodejavascript.com/tags/array |
| Dynamic Programming | https://leetcodejavascript.com/tags/dynamic-programming |
| Matrix | https://leetcodejavascript.com/tags/matrix |
| Stack | https://leetcodejavascript.com/tags/stack |
| Monotonic Stack | https://leetcodejavascript.com/tags/monotonic-stack |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow