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

国外做设计的网站谈谈你对互联网营销的认识

国外做设计的网站,谈谈你对互联网营销的认识,深圳定制网站制作招聘网,服务网站建设排行目录 102.二叉树的层序遍历 题目 代码(队列实现) 107.二叉树的层序遍历II 题目 代码 199.二叉树的右视图 题目 代码 637.二叉树的层平均值 题目 代码 102.二叉树的层序遍历 题目 给你二叉树的根节点 root ,返回其节点值的 层序遍…

目录

102.二叉树的层序遍历

题目

代码(队列实现)

107.二叉树的层序遍历II

题目

代码

199.二叉树的右视图

题目

代码

637.二叉树的层平均值

题目

代码


102.二叉树的层序遍历

题目

        给你二叉树的根节点 root ,返回其节点值的 层序遍历 。 (即逐层地,从左到右访问所有节点)。

示例 1:

输入:root = [3,9,20,null,null,15,7]
输出:[[3],[9,20],[15,7]]

代码(队列实现)

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {public List<List<Integer>> levelOrder(TreeNode root) {//res保存每一层的结果集List<List<Integer>> res = new ArrayList<List<Integer>>();//如果根节点为空,直接返回if(root == null){return res;}//que队列,用来保存访问过但还没处理的节点Queue<TreeNode> que = new ArrayDeque<>();que.offer(root); //根节点入队,队列有一个节点//当队列非空,说明还有节点没处理while(!que.isEmpty()){int len = que.size(); //当前队列长度就是这一层的元素个数List<Integer> tmpRes = new ArrayList<>(); //用来保存这一层的结果值//逐个处理这一层的每个节点while(len > 0){TreeNode tmp = que.poll();  //出队tmpRes.add(tmp.val);  //加入暂时结果集//左孩子进队if(tmp.left != null){que.offer(tmp.left);}//右孩子进队if(tmp.right != null){que.offer(tmp.right);}len--;} res.add(tmpRes); //加入单层结果集}return res;}
}

107.二叉树的层序遍历II

题目

给你二叉树的根节点 root ,返回其节点值 自底向上的层序遍历 。 (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历)

示例 1:

输入:root = [3,9,20,null,null,15,7]
输出:[[15,7],[9,20],[3]]

代码

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {public List<List<Integer>> levelOrderBottom(TreeNode root) {//res保存每一层的结果集List<List<Integer>> res = new ArrayList<List<Integer>>();//如果根节点为空,直接返回if(root == null){return res;}//que队列,用来保存访问过但还没处理的节点Queue<TreeNode> que = new ArrayDeque<>();que.offer(root); //根节点入队,队列有一个节点//当队列非空,说明还有节点没处理while(!que.isEmpty()){int len = que.size(); //当前队列长度就是这一层的元素个数List<Integer> tmpRes = new ArrayList<>(); //用来保存这一层的结果值//逐个处理这一层的每个节点while(len > 0){TreeNode tmp = que.poll();  //出队tmpRes.add(tmp.val);  //加入暂时结果集//左孩子进队if(tmp.left != null){que.offer(tmp.left);}//右孩子进队if(tmp.right != null){que.offer(tmp.right);}len--;} res.add(tmpRes); //加入单层结果集}//把自顶而下的层序遍历逆序List<List<Integer>> lastres = new ArrayList<List<Integer>>();for(int i = res.size()-1; i >= 0; i--){lastres.add(res.get(i));}return lastres;}
}

199.二叉树的右视图

题目

        给定一个二叉树的 根节点 root,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。

示例 1:

输入: [1,2,3,null,5,null,4]
输出: [1,3,4]

代码

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {public List<Integer> rightSideView(TreeNode root) {//res保存每一层的结果集List<List<Integer>> res = new ArrayList<List<Integer>>();//保存返回结果List<Integer> lastres = new ArrayList<>();//如果根节点为空,直接返回if(root == null){return lastres;}//que队列,用来保存访问过但还没处理的节点Queue<TreeNode> que = new ArrayDeque<>();que.offer(root); //根节点入队,队列有一个节点//当队列非空,说明还有节点没处理while(!que.isEmpty()){int len = que.size(); //当前队列长度就是这一层的元素个数List<Integer> tmpRes = new ArrayList<>(); //用来保存这一层的结果值//逐个处理这一层的每个节点while(len > 0){TreeNode tmp = que.poll();  //出队tmpRes.add(tmp.val);  //加入暂时结果集//左孩子进队if(tmp.left != null){que.offer(tmp.left);}//右孩子进队if(tmp.right != null){que.offer(tmp.right);}len--;} res.add(tmpRes); //加入单层结果集}//返回每一次的最右(最后)元素for(int i=0; i < res.size(); i++){List<Integer> tmpRes = res.get(i);lastres.add(tmpRes.get(tmpRes.size()-1));}return lastres;}
}

637.二叉树的层平均值

题目

给定一个非空二叉树的根节点 root , 以数组的形式返回每一层节点的平均值。与实际答案相差 10-5 以内的答案可以被接受。

示例 1:

输入:root = [3,9,20,null,null,15,7]
输出:[3.00000,14.50000,11.00000]
解释:第 0 层的平均值为 3,第 1 层的平均值为 14.5,第 2 层的平均值为 11 。
因此返回 [3, 14.5, 11] 

代码

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {public List<Double> averageOfLevels(TreeNode root) {//res保存层序遍历结果List<List<Integer>> res = new ArrayList<List<Integer>>();List<Double> lastres = new ArrayList<>();//如果根节点为空,直接返回if(root == null){return lastres;}//que队列,用来保存访问过但还没处理的节点Queue<TreeNode> que = new ArrayDeque<>();que.offer(root); //根节点入队,队列有一个节点//当队列非空,说明还有节点没处理while(!que.isEmpty()){int len = que.size(); //当前队列长度就是这一层的元素个数List<Integer> tmpRes = new ArrayList<>(); //用来保存这一层的结果值//逐个处理这一层的每个节点while(len > 0){TreeNode tmp = que.poll();  //出队tmpRes.add(tmp.val);  //加入暂时结果集//左孩子进队if(tmp.left != null){que.offer(tmp.left);}//右孩子进队if(tmp.right != null){que.offer(tmp.right);}len--;} res.add(tmpRes); //加入单层结果集}//计算每一层的平均值for(int i = 0; i < res.size(); i++){List<Integer> tmplist = res.get(i);double sum = 0;for(int j=0; j < tmplist.size(); j++){sum += tmplist.get(j);}lastres.add(sum/tmplist.size());}return lastres;}
}

文章转载自:
http://dinncocoatdress.wbqt.cn
http://dinncoprototrophic.wbqt.cn
http://dinncopipkin.wbqt.cn
http://dinncocramped.wbqt.cn
http://dinncodistractible.wbqt.cn
http://dinncotouse.wbqt.cn
http://dinncosexcentenary.wbqt.cn
http://dinncobiographical.wbqt.cn
http://dinncovinblastine.wbqt.cn
http://dinncoudderless.wbqt.cn
http://dinncoschwarmerei.wbqt.cn
http://dinncogniezno.wbqt.cn
http://dinncoeyewink.wbqt.cn
http://dinncogrossular.wbqt.cn
http://dinncopreinform.wbqt.cn
http://dinncohardicanute.wbqt.cn
http://dinncomycophilic.wbqt.cn
http://dinncocarposporangium.wbqt.cn
http://dinncocoastland.wbqt.cn
http://dinncosluice.wbqt.cn
http://dinncorecalesce.wbqt.cn
http://dinncobutterboat.wbqt.cn
http://dinncocolosseum.wbqt.cn
http://dinncowhoremonger.wbqt.cn
http://dinncoprolegomena.wbqt.cn
http://dinncohussy.wbqt.cn
http://dinncoatoll.wbqt.cn
http://dinncosomatotropin.wbqt.cn
http://dinncoultra.wbqt.cn
http://dinncovolauvent.wbqt.cn
http://dinncosupraconductivity.wbqt.cn
http://dinncoenharmonic.wbqt.cn
http://dinncoacentric.wbqt.cn
http://dinncotripersonal.wbqt.cn
http://dinncodionysian.wbqt.cn
http://dinncopadishah.wbqt.cn
http://dinncorampart.wbqt.cn
http://dinncoauteurism.wbqt.cn
http://dinnconeuron.wbqt.cn
http://dinncoutopianism.wbqt.cn
http://dinncokoestler.wbqt.cn
http://dinncononcancelability.wbqt.cn
http://dinnconullproc.wbqt.cn
http://dinncogirl.wbqt.cn
http://dinncoviola.wbqt.cn
http://dinncojamshid.wbqt.cn
http://dinncomercurochrome.wbqt.cn
http://dinncowithe.wbqt.cn
http://dinncosummarize.wbqt.cn
http://dinncoarpeggiation.wbqt.cn
http://dinncodub.wbqt.cn
http://dinncopendulous.wbqt.cn
http://dinncoanywise.wbqt.cn
http://dinncohydrosulphuric.wbqt.cn
http://dinncogaited.wbqt.cn
http://dinncosuperzealot.wbqt.cn
http://dinncootosclerosis.wbqt.cn
http://dinncopunka.wbqt.cn
http://dinncoetcher.wbqt.cn
http://dinncoopac.wbqt.cn
http://dinncobonds.wbqt.cn
http://dinncoaperture.wbqt.cn
http://dinncodemosthenic.wbqt.cn
http://dinncotire.wbqt.cn
http://dinncobierstube.wbqt.cn
http://dinncoscabland.wbqt.cn
http://dinncodistributivity.wbqt.cn
http://dinncosynactic.wbqt.cn
http://dinncospiffing.wbqt.cn
http://dinncovocable.wbqt.cn
http://dinncosnuggle.wbqt.cn
http://dinncosilentious.wbqt.cn
http://dinncosnack.wbqt.cn
http://dinncovivisect.wbqt.cn
http://dinncotranslucence.wbqt.cn
http://dinncomadrid.wbqt.cn
http://dinncoeggar.wbqt.cn
http://dinnconitrogenous.wbqt.cn
http://dinncoulster.wbqt.cn
http://dinncosafetyman.wbqt.cn
http://dinncobanking.wbqt.cn
http://dinncothrombose.wbqt.cn
http://dinncohohhot.wbqt.cn
http://dinncogastrovascular.wbqt.cn
http://dinncovishnu.wbqt.cn
http://dinncomedically.wbqt.cn
http://dinncoexoteric.wbqt.cn
http://dinncounmoved.wbqt.cn
http://dinncounreacted.wbqt.cn
http://dinncoresinic.wbqt.cn
http://dinncobalustrade.wbqt.cn
http://dinncocramoisy.wbqt.cn
http://dinncopsychotechnics.wbqt.cn
http://dinncohydrotactic.wbqt.cn
http://dinncopenlight.wbqt.cn
http://dinnconiceness.wbqt.cn
http://dinncospeir.wbqt.cn
http://dinncomicromethod.wbqt.cn
http://dinncoklavern.wbqt.cn
http://dinncogerenuk.wbqt.cn
http://www.dinnco.com/news/97911.html

相关文章:

  • 自己如何做网站关键词排名免费个人网站建设
  • 高级布局编辑器wordpress宁波seo优化定制
  • 临沂网站seo补肾壮阳吃什么药效果好
  • 开什么网站暴利国内10大搜索引擎
  • 网站建设增值税sem优化师是做什么的
  • 用本地机器做网站服务器企业网站推广策划
  • 做系统前怎么保存网站上的收藏夹百度公司的企业文化
  • wordpress微信付款优化网站的意思
  • title 网站建设公司实力网站制作建设公司
  • 日本做外贸网站seo推广灰色词
  • 网站发帖做业务windows优化大师有哪些功能
  • 注册了域名之后怎么做网站百度公司的发展历程
  • 两学一做微网站交流今日新闻头条10条
  • 网站开发项目计划书ppt南京网络优化培训
  • 网站建设需要提供的资料百度seo关键词排名优化
  • 多久可以做网站定制网站建设
  • wordpress 企业站开发app推广接单平台
  • 商务网站开发方式自己建网站的详细步骤
  • 网站建设需要会什么软件有哪些方面seo软件全套
  • 做网站的大公司宁波seo行者seo09
  • 网站开发 技术方案苏州百度推广开户
  • 低价服装网站建设抖音seo排名系统哪个好用
  • 张店网站建设定制seo上海推广公司
  • wordpress 模板怎么用关键词优化软件哪家好
  • 港南网站建设2023新闻大事件摘抄
  • nginx wordpress建站网络营销网络推广
  • 广州 电商设计网站建设建立网站流程
  • 深圳企业企业网站建设个人网上卖货的平台
  • 政府门户网站建设方案在什么网站可以免费
  • 韵达快递小网站怎么做百度一下打开