wordpress动漫主题秦皇岛seo排名

news/2025/10/8 22:52:59/文章来源:
wordpress动漫主题,秦皇岛seo排名,装修平台合作,网页搜索二叉树相关推荐 107.二叉树的层次遍历II199.二叉树的右视图637.二叉树的层平均值429.N叉树的层序遍历515.在每个树行中找最大值116.填充每个节点的下一个右侧节点指针117.填充每个节点的下一个右侧节点指针II总结 107.二叉树的层次遍历II 切片本质是一个结构体#xff0c;包含… 二叉树相关推荐 107.二叉树的层次遍历II199.二叉树的右视图637.二叉树的层平均值429.N叉树的层序遍历515.在每个树行中找最大值116.填充每个节点的下一个右侧节点指针117.填充每个节点的下一个右侧节点指针II总结 107.二叉树的层次遍历II 切片本质是一个结构体包含一个指向底层数组的指针(prt)长度len容量cap。如果通过函数对切片进行赋值修改会传递到函数外但如果在函数内对切片进行扩容会产生新的底层数组但数组外的切片仍指向原来的旧切片进而导致对切片的修改无法传递到函数外 (1)递归 func levelOrderBottom(root *TreeNode) [][]int {res : [][]int{}var help func(root *TreeNode, depth int) help func(root *TreeNode, depth int) {if root nil {return}if depth len(res) {res append(res, []int{})}res[depth] append(res[depth], root.Val)depthhelp(root.Left, depth)help(root.Right, depth)} help(root, 0)for i, j : 0, len(res) - 1; i j; i, j i 1, j - 1 {res[i], res[j] res[j], res[i]}return res } (2)层序 func levelOrderBottom(root *TreeNode) [][]int {res : [][]int{}if root nil {return res}node : rootqueue : []*TreeNode{root}for len(queue) 0 {size : len(queue)vals : []int{}for i : 0; i size; i {node queue[0]queue queue[1:]vals append(vals, node.Val)if node.Left ! nil {queue append(queue, node.Left)}if node.Right ! nil {queue append(queue, node.Right)}}// 反向插入结果res append(res, []int{})copy(res[1:], res[0:])res[0] vals}return res }199.二叉树的右视图 (1)递归 中—右—左顺序访问保证了每层最先访问的是最右边节点 如果当前节点的高度等于len(res)将其值加入res。当前节点类似于为res扩张探路。 func rightSideView(root *TreeNode) []int {res : []int{}var help func(root *TreeNode, depth int)help func(root *TreeNode, depth int) {if root nil {return}if depth len(res) {res append(res, root.Val)}depthhelp(root.Right, depth)help(root.Left, depth)}help(root, 0)return res }(2)层序 func rightSideView(root *TreeNode) []int {res : []int{}if root nil {return res}curQueue : []*TreeNode{root}for len(curQueue) 0 {nextQueue : []*TreeNode{}size : len(curQueue)for i : 0; i size; i {node : curQueue[i]if node.Left ! nil {nextQueue append(nextQueue, node.Left)}if node.Right ! nil {nextQueue append(nextQueue, node.Right)}if i size - 1 {res append(res, node.Val)}}curQueue nextQueue}return res }637.二叉树的层平均值 (1)递归 创建结构体nodeGroup存储当前层node个数和sum 类似上题解法若当前节点高度小于len(nodeGroup)对当前层nodeGroup的count和sum进行更新【count1,sumroot.val】若当前节点高度等于len(nodeGroup)创建新的层并对count和sum赋值【count1,sumroot.val】。 type nodeGroup struct {Count intsum int }func averageOfLevels(root *TreeNode) []float64 {res : []float64{}resGroup : []nodeGroup{{0, 0}}var help func(root *TreeNode, depth int)help func(root *TreeNode, depth int) {if root nil {return}if depth len(resGroup) {resGroup[depth].CountresGroup[depth].sum root.Val} else {resGroup append(resGroup, nodeGroup{1, root.Val})}depthhelp(root.Left, depth)help(root.Right, depth)}help(root, 0)for _, countSum : range resGroup {avg : float64(countSum.sum) / float64(countSum.Count)res append(res, avg)}return res }(2)层序 func averageOfLevels(root *TreeNode) []float64 {res : []float64{}curQueue : []*TreeNode{root}for len(curQueue) 0 {size : len(curQueue)sum : 0nextQueue : []*TreeNode{}for _, node : range curQueue {sum node.Valif node.Left ! nil {nextQueue append(nextQueue, node.Left)}if node.Right ! nil {nextQueue append(nextQueue, node.Right)}}res append(res, float64(sum)/float64(size))curQueue nextQueue}return res }429.N叉树的层序遍历 (1)递归追加当前层数据如果当前节点高度等于len(res)创建新层。 func levelOrder(root *Node) [][]int {res : [][]int{}var help func(root *Node, depth int)help func(root *Node, depth int) {if root nil {return }if depth len(res) {res append(res, []int{})}res[depth] append(res[depth], root.Val)depthfor _, child : range root.Children {help(child, depth)}}help(root, 0)return res }(2)迭代创建新层追加数据。 func levelOrder(root *Node) [][]int {res : [][]int{}if root nil {return res}curQueue : []*Node{root}depth : 0for len(curQueue) 0 {nextQueue : []*Node{}res append(res, []int{})for _, node : range curQueue {res[depth] append(res[depth], node.Val)for _, child : range node.Children {nextQueue append(nextQueue, child)}}depthcurQueue nextQueue}return res }515.在每个树行中找最大值 (1)递归 func largestValues(root *TreeNode) []int {res : []int{}var help func(root *TreeNode, depth int) help func(root *TreeNode, depth int) {if root nil {return}if depth len(res) {res append(res, root.Val)}if root.Val res[depth] {res[depth] root.Val}depthhelp(root.Left, depth)help(root.Right,depth)return}help(root, 0)return res }(2)迭代 func largestValues(root *TreeNode) []int {res : []int{}if root nil {return res}depth : 0curQueue : []*TreeNode{root}for len(curQueue) 0 {nextQueue : []*TreeNode{}for _, node : range curQueue {if depth len(res) {res append(res, node.Val)}if node.Val res[depth] {res[depth] node.Val}if node.Left ! nil {nextQueue append(nextQueue, node.Left)}if node.Right ! nil {nextQueue append(nextQueue, node.Right)}}depthcurQueue nextQueue}return res }116.填充每个节点的下一个右侧节点指针 (1)递归如果当前节点高度等于len(res)证明该节点是最新一层最左侧节点将其追加到res中否则将res[depth]节点指向当前节点并更新res[depth]为当前节点 func connect(root *Node) *Node {res : []*Node{}var help func(root *Node, depth int) help func (root *Node, depth int) {if root nil {return}if depth len(res) {res append(res, root)} else {res[depth].Next rootres[depth] root}depthhelp(root.Left, depth)help(root.Right, depth)}help(root, 0)return root }(2)迭代 func connect(root *Node) *Node {if root nil {return root}curQueue : []*Node{root}for len(curQueue) 0 {nextQueue : []*Node{}size : len(curQueue)for i : 0; i size; i {node : curQueue[i]if node.Left ! nil {nextQueue append(nextQueue, node.Left)}if node.Right ! nil {nextQueue append(nextQueue, node.Right)}if i size - 1 {break}node.Next curQueue[i 1]}curQueue nextQueue}return root }117.填充每个节点的下一个右侧节点指针II 题解只能说与上题一模一样 总结 树递归层序迭代一个套路走完所有题 大佬递归方法太秀了必须码住

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/932028.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

vue 组件的常见8种通信方式

1、通过props传递‌,emit触发自定义事件: 父传子:子组件中通过props接收父组件传递的数据。 ‌子传父:子组件通过emit触发一个事件,父组件监听这个事件来接收数据。 vue2:通过props和$emit vue3:script中setup,…

技能训练企业网站建设可行性分析企业网站建设 百度文库

文章目录 参考环境常量数组不可变性版本限制 constdefine()构造大小写不敏感的常量$case_insensitive 参数PHP7.3PHP8 若 define() 在不支持常量数组的版本中运行 参考 项目描述搜索引擎Bing、GoogleAI 大模型文心一言、通义千问、讯飞星火认知大模型、ChatGPTPHP 手册PHP Man…

251008

251008美好的一天从现在开始

vue一键安装

vue一键安装 Microsoft Windows [版本 10.0.26100.4946] (c) Microsoft Corporation。保留所有权利。F:\vue_flask_project\vue_flask_project_one\vue>npm install --global vue-cli npm warn deprecated inflight…

佛山网站建设找哪家wordpress 中文版下载

内联式css样式,直接写在现有的HTML标签中 CSS样式可以写在哪些地方呢?从CSS 样式代码插入的形式来看基本可以分为以下3种:内联式、嵌入式和外部式三种。这一小节先来讲解内联式。 内联式css样式表就是把css代码直接写在现有的HTML标签中&am…

权威的网站建设排行榜男科医院哪家正规医院

模拟伪造请求 方法一:打断点模拟HTTP请求 1、浏览器页面填好内容后(不要操作提交),打开fiddler,设置请求前断点,点击菜单fiddler,”Rules”\”Automatic Breakpoints”\”Before Requests” 2、在页面上点…

做网站卖电脑oss cdn wordpress

目录 一、Vite概述 二、Vite构建Vue3工程化项目 三、ViteVue3项目目录结构 四、ViteVue3项目组件(SFC入门) 五、ViteVue3样式导入方式 六、ViteVue3响应式数据和setup语法糖 一、Vite概述 Vite是一种新型前端构建工具,能够显著提升前端开发体验;Vite结合…

网站页面设计要求wordpress快速登陆插件

动机(Motivate): 在软件构建过程中,一个请求可能被多个对象处理,但是每个请求在运行时只能有一个接受者,如果显示指定,将必不可少地带来请求发送者与接受者的紧耦合。 如何使请求的发送者不需要指定具体的接受…

如何使用 ManySpeech 调用 SenseVoiceSmall 模型

一、模型与组件简介SenseVoice 模型多语言音频理解开源模型,支持语音识别、语种识别、情感识别等功能,适用于中、粤、英、日、韩等语言。 ManySpeech.AliParaformerAsrC# 语音识别推理库,支持 paraformer-large、pa…

北京免费发布企业信息网站建设网站哪家强

vmware与windows共享文件夹 宗旨:技术的学习是有限的,分享的精神是无限的。 虚拟工具安装好之后,我们就可以在windows和linux设置一个共享目录了,继续看图干活。 设置好共享目录以后,打开终端输入以下命令,就可以再…

维基框架 (Wiki Framework) v1.1.2 | 企业级微服务开发框架

Release Notes 版本修复日志【修复】修复HTTPS请求参数ContentType创建错误问题; 【修复】修复用户接口类 IUserDetailsService 被删除问题; 【修复】修复Spring Boot 全局响应处理增加对返回字符串兼容; 【修复】修…

宁夏公路建设局网站wordpress 中国风

Dubbo 支持哪些协议,每种协议的应用场景,优缺点? • dubbo: 单一长连接和 NIO 异步通讯,适合大并发小数据量的服务调用,以及消费者远大于提供者。传输协议 TCP,异步,Hessian 序列化…

如何将 iOS 性能调试融入日常创建流程?构建“默认监控机制”的实战经验(含 KeyMob 程序搭配)

如何将 iOS 性能调试融入日常创建流程?构建“默认监控机制”的实战经验(含 KeyMob 程序搭配)2025-10-08 22:32 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !imp…

国庆假期总结

🎉国庆总览🎉 学习🎯被学习充满的假期真是太充实(无聊)了机器学习。学习了吴恩达的机器学习,看了一百多集,实践做了小部分,我感觉到只学习到了皮毛,难的。其实只是选修课而已在这个学期,但是我想这是专业…

wordpress双语网站响应式网站开发实例

/任务2:if else 语句 编写控制台java程序,模拟银行取款的功能。 使用Scanner对象相关方法从控制台接收用户输入的银行卡账号和密码, 与预先定义好的银行卡账号密码相同则输出用户名密码正确,可以取款;如果账号或者密码…

普宁17网站一起做淘宝wordpress 评论 正在提交_请稍后

耳机自从手机出世之后就一直伴随着我们,作为手机的最佳搭档被我们使用,像现如今流行的蓝牙耳机我们就经常使用,大学生也是差不多每天都用得着,听歌、散步、玩游戏、看剧等哪都看得到它的身影,当然蓝牙耳机价格也有高低…

CF1738E Balance Addicts

Sol 神秘题目。 定义 \(pre_i=pre_{i-1}+a_i,suf_i=suf_{i+1}+a_{i+1}\)。 显然一个方案如果合法,\((i,i+1),(j,j+1)\) 位置均没有备选且满足 \(pre_i=suf_j\),那么加上 \((i,i+1),(j,j+1)\) 也同样合法。 所以考虑极…

2025浇注型聚氨酯厂家最新推荐榜:聚氨酯胶黏剂/聚氨酯胶辊/聚氨酯制品/聚氨酯原料/液体聚氨酯/聚氨酯浇注料/聚氨酯ABC料/浇筑聚氨酯/聚氨酯预聚物全场景实力厂家

在当今工业材料领域,浇注型聚氨酯作为一种高性能弹性体材料,因其优异的耐磨性、耐油性和机械强度,在机械制造、矿山设备、印刷包装等行业得到广泛应用。随着市场需求持续增长,如何从众多厂家中筛选出优质供应商成为…

优化 IIS 应用程序池配置,告别 ASP.NET 冷启动延迟

优化 IIS 应用程序池配置,告别 ASP.NET 冷启动延迟📌 摘要 在默认配置下,IIS 的 ASP.NET 应用程序池会在闲置 20 分钟后自动关闭。当下一个用户请求到达时,系统需要重新启动应用池并加载应用程序——这个过程就是…

C语言设计模式-策略模式

C语言,设计模式,策略模式#include <stdio.h> #include <stdlib.h>typedef signed int int32_t;void swap(int *a, int *b) {int tmp;tmp = *a;*a = *b;*b = tmp; }void print_arr(int arr[], int32_t le…