news 2026/7/26 5:37:12

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/7/17 5:37:48

2025LLM核心架构进展复盘:Attn与MOE研究精选(收藏版)

本文回顾了2025年大模型&#xff08;LLM&#xff09;在注意力机制&#xff08;Attn&#xff09;和专家混合&#xff08;MOE&#xff09;方面的核心架构进展。重点介绍了TPA、MoBA、NSA等创新方法&#xff0c;如低秩压缩KVcache、Top-k block注意力、原生稀疏注意力等&#xff0…

作者头像 李华
网站建设 2026/7/23 19:52:14

导师推荐!AI论文写作软件 千笔·专业论文写作工具 VS speedai 本科生专属

随着人工智能技术的迅猛迭代与普及&#xff0c;AI辅助写作工具已逐步渗透到高校学术写作场景中&#xff0c;成为本科生、研究生完成毕业论文不可或缺的辅助手段。越来越多面临毕业论文压力的学生&#xff0c;开始依赖各类AI工具简化写作流程、提升创作效率。但与此同时&#xf…

作者头像 李华
网站建设 2026/7/17 15:35:48

原理详解:XinServer 是如何做到接口一键生成的?

原理详解&#xff1a;XinServer 是如何做到接口一键生成的&#xff1f; 不知道你有没有过这种经历&#xff1a;产品经理拿着原型图过来&#xff0c;说下周一要上线一个内部管理系统&#xff0c;需要用户管理、部门管理、权限控制&#xff0c;外加一堆业务表单。你心里一咯噔&am…

作者头像 李华
网站建设 2026/7/17 11:44:33

用实力说话千笔·专业降AI率智能体,全网顶尖的降AIGC网站

在AI技术迅速渗透学术写作领域的今天&#xff0c;越来越多的本科生开始借助AI工具提升论文写作效率。然而&#xff0c;随着各大查重系统对AI生成内容的识别能力不断提升&#xff0c;如何有效降低论文中的AIGC率和重复率&#xff0c;已成为困扰无数学生的难题。面对市场上琳琅满…

作者头像 李华