Title: #427 - Construct Quad Tree - LeetCode JavaScript Solutions
Open Graph Title: #427 - Construct Quad Tree - LeetCode JavaScript Solutions
X Title: #427 - Construct Quad Tree - LeetCode JavaScript Solutions
Description: Given a n * n matrix grid of 0's and 1's only. We want to represent grid with a Quad-Tree. Return the root of the Quad-Tree repres...
Open Graph Description: Given a n * n matrix grid of 0's and 1's only. We want to represent grid with a Quad-Tree. Return the root of the Quad-Tree repres...
X Description: Given a n * n matrix grid of 0's and 1's only. We want to represent grid with a Quad-Tree. Return the root of the Quad-Tree repres...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/construct-quad-tree
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/construct-quad-tree","name":"#427 - Construct Quad Tree - LeetCode JavaScript Solutions","description":"Given a n * n matrix grid of 0's and 1's only. We want to represent grid with a Quad-Tree. Return the root of the Quad-Tree repres...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * // Definition for a QuadTree node.\n * function _Node(val,isLeaf,topLeft,topRight,bottomLeft,bottomRight) {\n * this.val = val;\n * this.isLeaf = isLeaf;\n * this.topLeft = topLeft;\n * this.topRight = topRight;\n * this.bottomLeft = bottomLeft;\n * this.bottomRight = bottomRight;\n * };\n */\n\n/**\n * @param {number[][]} grid\n * @return {_Node}\n */\nvar construct = function(grid) {\n return build(0, 0, grid.length);\n\n function build(x, y, n) {\n const value = grid[x][y];\n for (let i = x; i < x + n; i++) {\n for (let j = y; j < y + n; j++) {\n if (grid[i][j] !== value) {\n n /= 2;\n return new _Node(true, false,\n build(x, y, n),\n build(x, y + n, n),\n build(x + n, y, n),\n build(x + n, y + n, n)\n );\n }\n }\n }\n return new _Node(value === 1, true, null, null, null, null);\n }\n};","keywords":"LeetCode 427, #427 - Construct Quad Tree, Medium, 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/construct-quad-tree |
| 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/construct-quad-tree/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0427-construct-quad-tree.js |
| Array | https://leetcodejavascript.com/tags/array |
| Matrix | https://leetcodejavascript.com/tags/matrix |
| Tree | https://leetcodejavascript.com/tags/tree |
| Divide and Conquer | https://leetcodejavascript.com/tags/divide-and-conquer |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow