当前位置: 首页 > news >正文

day82(2.10)——leetcode面试经典150

427. 建立四叉树

427. 建立四叉树

这个题目把我吓到了哈哈哈 如此之多

题目:

题解:

/* // Definition for a QuadTree node. class Node { public boolean val; public boolean isLeaf; public Node topLeft; public Node topRight; public Node bottomLeft; public Node bottomRight; public Node() { this.val = false; this.isLeaf = false; this.topLeft = null; this.topRight = null; this.bottomLeft = null; this.bottomRight = null; } public Node(boolean val, boolean isLeaf) { this.val = val; this.isLeaf = isLeaf; this.topLeft = null; this.topRight = null; this.bottomLeft = null; this.bottomRight = null; } public Node(boolean val, boolean isLeaf, Node topLeft, Node topRight, Node bottomLeft, Node bottomRight) { this.val = val; this.isLeaf = isLeaf; this.topLeft = topLeft; this.topRight = topRight; this.bottomLeft = bottomLeft; this.bottomRight = bottomRight; } } */ class Solution { public Node construct(int[][] grid) { int n = grid.length; return build(grid, 0, n-1, 0, n-1); } Node build(int[][] grid, int l1, int r1, int l2, int r2) { int flag = 0; int d = grid[l1][l2]; for(int i=l1;i<=r1;i++) { for(int j=l2;j<=r2;j++) { if(grid[i][j]!=d) { flag=1; break; } } if(flag==1) { break; } } //如果该区域都相等,直接返回Node if(flag==0) { return new Node(d == 1, true); } int mid1 = (l1+r1)/2; int mid2 = (l2+r2)/2; Node tL = build(grid, l1, mid1, l2, mid2); Node tR = build(grid, l1, mid1, mid2+1, r2); Node bL = build(grid, mid1+1, r1, l2, mid2); Node bR = build(grid, mid1+1, r1, mid2+1, r2); return new Node(false, false, tL, tR, bL, bR); } }
http://www.jsqmd.com/news/366647/

相关文章:

  • 实测才敢推 8个降AIGC工具:继续教育降AI率全维度测评
  • AI 对话也要看广告?OpenAI 正式测试 ChatGPT 广告系统
  • WebP 转 JPG 在线工具怎么选?几款实用网站对比推荐
  • 2026 南昌英语雅思培训教育机构推荐|雅思培训课程中心权威口碑榜单 - 老周说教育
  • 免费好用!2026AI 论文工具排行榜,新手直接抄作业
  • R-Meta分析核心技术:从热点挖掘到高级模型、助力高效科研与论文发表 - 教程
  • 成都、天津、大连、珠海:养老工作分析 by Claude Opus 4.6
  • OpenCSG(开放传神)赋能软件研发:某金融软件公司用AI Coding把研发效率提升40%
  • 2026 AI论文工具黑马榜!实测后,真正好用的都在这
  • 贵州工业地坪一站式解决方案指南,专业服务看贵州惠博特装饰材料有限公司 - 深度智识库
  • 尺寸智能管理:制造业质量变革的隐性引擎
  • 影视剪辑素材网站推荐,海量高清视频素材,剪辑师必备素材网 - 品牌2026
  • 2026 南昌英语雅思培训教育机构推荐、雅思培训课程中心权威口碑榜单 - 老周说教育
  • 【春招必看】一次性入门openlayers和cesium两个地图开发框架
  • AI训练素材及数据集供应商推荐:卓特视觉专业AI训练素材供应商 - 品牌2026
  • 2025LLM核心架构进展复盘:Attn与MOE研究精选(收藏版)
  • 高端制造首选!2026国产颗粒计数器厂家推荐清单 - 品牌推荐大师1
  • 小白程序员轻松入门:LinearRAG如何革新大模型知识检索?
  • c#ref和out
  • poll() Missing ‘window‘ in context File解决办法 blender插件开发
  • 2026 南通英语雅思培训教育机构推荐;雅思培训课程中心权威口碑榜单 - 老周说教育
  • 应用日志收集与 logrotate 切割配置
  • 大模型推理,不再是“一根筋”
  • 2026 南昌英语雅思培训教育机构推荐:雅思培训课程中心权威口碑榜单 - 老周说教育
  • 推理性能PK,华为+DeepSeek>英伟达?
  • 想让AI更智能?收藏这篇,小白也能学会调用工具的Agent智能体!
  • 2026 厦门英语雅思培训教育机构推荐:雅思培训课程中心权威口碑榜单 - 老周说教育
  • (2026年最新)AI大模型学习路线图详解:从入门到精通,你的完整学习指南!_大模型学习路线
  • 【课程设计/毕业设计】基于SpringBoot框架的食品安全服务系统基于springboot的食品安全监测及风险预警系统的设计与实现【附源码、数据库、万字文档】
  • 2026年IT圈最火话题:AI智能体与鸿蒙生态大爆发!你抓住机会了吗?