news 2026/4/27 12:26:52

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

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
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); } }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/23 14:33:02

【春招必看】一次性入门openlayers和cesium两个地图开发框架

春节过后&#xff0c;即将迎来26年毕业季&#xff0c;选择就业的同学&#xff0c;如果还没拿到offer&#xff0c;就要开始准备26年春招了。如果想找WebGIS相关的岗位&#xff0c;可以通过招聘信息&#xff0c;了解到企业的具体要求。其中&#xff0c;openlayers和cesium有多重要…

作者头像 李华
网站建设 2026/4/19 19:50:43

LLM 联网搜索,到底是咋回事?

0x0 序 近段时间 DeepSeek 的服务火遍了全网&#xff0c;无论是使用网页还是使用 App 都能享受到 深度思考 联网搜索 的至尊体验。奈何免费的东西往往是需要排队的&#xff0c;从年开始 DeepSeek 的服务就一度处于不可用状态&#xff0c;就算是年后&#xff0c;网络搜索也是经…

作者头像 李华
网站建设 2026/4/20 1:24:14

万字详解大模型推理加速核心原理丨茶思AI推理

本期聚焦】万字详解大模型推理加速分形原理&#xff0c;重塑资源优化体系&#xff1b;月之暗面发布Kimi K2.5&#xff0c;实现AI推理从“单体思考”到“集群作战”进化&#xff1b;Hyper3D Rodin Gen-2 Edit上线&#xff0c;3D生成推理迈入可编辑时代&#xff1b;人大联合团队发…

作者头像 李华
网站建设 2026/4/25 5:44:08

Java毕设项目:基于springboot的食品安全监测及风险预警系统的设计与实现(源码+文档,讲解、调试运行,定制等)

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华
网站建设 2026/4/26 14:13:37

刷爆kafka经典面试题100道覆盖全场景!

1:Kafka 是什么?它的主要应用场景有哪些? kafka是什么? Kafka是一种分布式流事件处理平台,最初由领英开发开发,现在是 Apache 基金会的一部分。编写语言是主要是Scala和一些底层和性能模块Java编写。 它的核心功能主要包括消息队列、流处理和数据集成。…

作者头像 李华