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

网站收录后才可以做排名吗免费的大数据分析平台

网站收录后才可以做排名吗,免费的大数据分析平台,大数据培训哪家好,最好的域名注册网站1,力扣102 给你二叉树的根节点 root ,返回其节点值的 层序遍历 。 (即逐层地,从左到右访问所有节点)。 示例 1: 输入:root [3,9,20,null,null,15,7] 输出:[[3],[9,20],[15,7]]示例…

1,力扣102

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

示例 1:

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

示例 2:

输入:root = [1]
输出:[[1]]

示例 3:

输入:root = []
输出:[]

提示:

  • 树中节点数目在范围 [0, 2000] 内
  • -1000 <= Node.val <= 1000
/*** 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) {List<List<Integer>> res = new ArrayList<List<Integer>>();//二维数组存数据Queue<TreeNode>que = new LinkedList<TreeNode>();//借助队列if(root==null) return res;que.offer(root);while(!que.isEmpty()){//遍历每一层int len = que.size();//用于记录每一层节点的个数List<Integer>list = new ArrayList<>();while(len>0){//对每一层数据进行处理TreeNode t = que.poll();list.add(t.val);//收集一层数据if(t.left!=null) que.offer(t.left);if(t.right!=null) que.offer(t.right);len--;}res.add(list);//收集一整层数据}return res;}
}

2,力扣107 二叉树遍历II

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

示例 1:

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

示例 2:

输入:root = [1]
输出:[[1]]

示例 3:

输入:root = []
输出:[]

提示:

  • 树中节点数目在范围 [0, 2000] 内
  • -1000 <= Node.val <= 1000
/*** 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) {List<List<Integer>> res = new ArrayList<List<Integer>>();Queue<TreeNode> que= new LinkedList<>();if(root==null) return res;que.offer(root);while(!que.isEmpty()){int len = que.size();List<Integer>list = new ArrayList<>();while(len > 0){TreeNode t = que.poll();list.add(t.val);if(t.left!=null) que.offer(t.left);if(t.right!=null) que.offer(t.right);len--;}res.add(list);}Collections.reverse(res);//将res逆置一下即可return res;}
}

3, 力扣199

二叉树的右视图

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

示例 1:

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

示例 2:

输入: [1,null,3]
输出: [1,3]

示例 3:

输入: []
输出: []

提示:

  • 二叉树的节点个数的范围是 [0,100]
  • -100 <= Node.val <= 100 
/*** 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) {List<Integer> res = new ArrayList<>();Queue<TreeNode>que = new LinkedList<TreeNode>();//借助队列if(root==null) return res;que.offer(root);while(!que.isEmpty()){//遍历每一层int len = que.size();//用于记录每一层节点的个数while(len>0){//对每一层数据进行处理TreeNode t = que.poll();if(len==1){res.add(t.val);//只收集每一层的最后一个节点的值}if(t.left!=null) que.offer(t.left);if(t.right!=null) que.offer(t.right);len--;}}return res;}
}

 4,力扣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] 。

示例 2:

输入:root = [3,9,20,15,7]
输出:[3.00000,14.50000,11.00000]

提示:

  • 树中节点数量在 [1, 104] 范围内
  • -231 <= Node.val <= 231 - 1
/*** 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) {List<Double> res = new ArrayList<>();Queue<TreeNode>que = new LinkedList<TreeNode>();//借助队列if(root==null) return res;que.offer(root);while(!que.isEmpty()){//遍历每一层int len = que.size();//用于记录每一层节点的个数int size = len;//记录len,一会算平均值做分母,double sum = 0;while(len>0){//对每一层数据进行处理TreeNode t = que.poll();sum+=t.val;if(t.left!=null) que.offer(t.left);if(t.right!=null) que.offer(t.right);len--;}double ave = sum/size;res.add(ave);}return res;}
}

5, 力扣429   N叉树的层序遍历

 

给定一个 N 叉树,返回其节点值的层序遍历。(即从左到右,逐层遍历)。

树的序列化输入是用层序遍历,每组子节点都由 null 值分隔(参见示例)。

示例 1:

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

示例 2:

输入:root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]
输出:[[1],[2,3,4,5],[6,7,8,9,10],[11,12,13],[14]]

提示:

  • 树的高度不会超过 1000
  • 树的节点总数在 [0, 10^4] 之间

 

/*
// Definition for a Node.
class Node {public int val;public List<Node> children;public Node() {}public Node(int _val) {val = _val;}public Node(int _val, List<Node> _children) {val = _val;children = _children;}
};
*/class Solution {public List<List<Integer>> levelOrder(Node root) {List<List<Integer>> res = new ArrayList<List<Integer>>();//二维数组存数据Queue<Node>que = new LinkedList<Node>();//借助队列if(root==null) return res;que.offer(root);while(!que.isEmpty()){//遍历每一层int len = que.size();//用于记录每一层节点的个数List<Integer>list = new ArrayList<>();while(len>0){//对每一层数据进行处理Node t = que.poll();list.add(t.val);//收集一层数据for(Node child : t.children){//把每个节点的孩子都送进队列que.offer(child);}len--;}res.add(list);//收集一整层数据}return res;}
}

5, 力扣515 找每个树行的最大值

 

给定一棵二叉树的根节点 root ,请找出该二叉树中每一层的最大值。

示例1:

输入: root = [1,3,2,5,3,null,9]
输出: [1,3,9]

示例2:

输入: root = [1,2,3]
输出: [1,3]

提示:

  • 二叉树的节点个数的范围是 [0,104]
  • -231 <= Node.val <= 231 - 1
/*** 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> largestValues(TreeNode root) {List<Integer> res = new ArrayList<>();Queue<TreeNode>que = new LinkedList<TreeNode>();//借助队列if(root==null) return res;que.offer(root);while(!que.isEmpty()){//遍历每一层int len = que.size();//用于记录每一层节点的个数  int max = Integer.MIN_VALUE; //使用这种初始化方式的场景通常出现在需要通过比较来找到一个数列中的最大值时        while(len>0){//对每一层数据进行处理TreeNode t = que.poll();if(t.val > max){max = t.val;}if(t.left!=null) que.offer(t.left);if(t.right!=null) que.offer(t.right);len--;}res.add(max);//收集一整层数据}return res;}
}

6,填充每个节点的下一个右侧节点指针

116.填充每个节点的下一个右侧节点指针

力扣题目链接(opens new window)

给定一个完美二叉树,其所有叶子节点都在同一层,每个父节点都有两个子节点。二叉树定义如下:

struct Node {int val;Node *left;Node *right;Node *next;
}

1
2
3
4
5
6

填充它的每个 next 指针,让这个指针指向其下一个右侧节点。如果找不到下一个右侧节点,则将 next 指针设置为 NULL。

初始状态下,所有 next 指针都被设置为 NULL。

116.填充每个节点的下一个右侧节点指针

/*
// Definition for a Node.
class Node {public int val;public Node left;public Node right;public Node next;public Node() {}public Node(int _val) {val = _val;}public Node(int _val, Node _left, Node _right, Node _next) {val = _val;left = _left;right = _right;next = _next;}
};
*/class Solution {public Node connect(Node root) {Queue<Node>que = new LinkedList<Node>();//借助队列if(root==null) return root;que.offer(root);while(!que.isEmpty()){//遍历每一层int len = que.size();//用于记录每一层节点的个数while(len>0){//对每一层数据进行处理Node t = que.poll();Node tnext = que.peek();//记录t的下一个节点if(len==1){//每一层的最后一个节点,之后没有节点t.next = null;}else{//后面有节点,则指向后节点t.next = tnext;}if(t.left!=null) que.offer(t.left);if(t.right!=null) que.offer(t.right);len--;}}return root;}
}

7,104.二叉树的最大深度

104.二叉树的最大深度

力扣题目链接(opens new window)

给定一个二叉树,找出其最大深度。

二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。

说明: 叶子节点是指没有子节点的节点。

示例:

给定二叉树 [3,9,20,null,null,15,7],

104. 二叉树的最大深度

返回它的最大深度 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 int maxDepth(TreeNode root) {if(root==null) return 0;Queue<TreeNode>que = new LinkedList<TreeNode>();//借助队列que.offer(root);int depth=0;//记录深度,初始化为0while(!que.isEmpty()){//遍历每一层int len = que.size();//用于记录每一层节点的个数List<Integer>list = new ArrayList<>();while(len>0){//对每一层数据进行处理TreeNode t = que.poll();list.add(t.val);//收集一层数据if(t.left!=null) que.offer(t.left);if(t.right!=null) que.offer(t.right);len--;}depth++;//一次遍历完,深度加1}return depth;}
}
/*** 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 int maxDepth(TreeNode root) {if(root == null) return 0;return 1+Math.max(maxDepth(root.left),maxDepth(root.right));}
}

8,力扣111, 给定一个二叉树,找出其最小深度

给定一个二叉树,找出其最小深度。

最小深度是从根节点到最近叶子节点的最短路径上的节点数量。

说明:叶子节点是指没有子节点的节点。

示例 1:

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

示例 2:

输入:root = [2,null,3,null,4,null,5,null,6]
输出:5

提示:

  • 树中节点数的范围在 [0, 105] 内
  • -1000 <= Node.val <= 1000
/*** 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 int minDepth(TreeNode root) {Queue<TreeNode>que = new LinkedList<TreeNode>();//借助队列if(root==null) return 0;que.offer(root);int depth = 0;while(!que.isEmpty()){//遍历每一层int len = que.size();//用于记录每一层节点的个数depth++;//注意这里先深度加一,不能在第二个循环之后++,因为万一就一个节点,就会在下面depth返回出来为0,是错的while(len>0){//对每一层数据进行处理TreeNode t = que.poll();if(t.left!=null) que.offer(t.left);if(t.right!=null) que.offer(t.right);if(t.left==null&&t.right==null){return depth;}len--;}}return depth;}
}

 

 

 

 

 

 

 

 


文章转载自:
http://dinncopathogenic.tpps.cn
http://dinncoextralegal.tpps.cn
http://dinncoslather.tpps.cn
http://dinncooutrush.tpps.cn
http://dinncopreferment.tpps.cn
http://dinnconautophone.tpps.cn
http://dinncoconcealment.tpps.cn
http://dinncocrackbrain.tpps.cn
http://dinncocravenette.tpps.cn
http://dinncoelectropult.tpps.cn
http://dinncocactaceous.tpps.cn
http://dinnconeocolonialism.tpps.cn
http://dinncolaminitis.tpps.cn
http://dinncodeclassee.tpps.cn
http://dinncotransmutation.tpps.cn
http://dinncogeomorphic.tpps.cn
http://dinncoturpan.tpps.cn
http://dinncocinnabar.tpps.cn
http://dinncodiplomaism.tpps.cn
http://dinncoendotoxin.tpps.cn
http://dinncochukchee.tpps.cn
http://dinncoweregild.tpps.cn
http://dinncoerratically.tpps.cn
http://dinncolealty.tpps.cn
http://dinncoautoloading.tpps.cn
http://dinncostem.tpps.cn
http://dinncovim.tpps.cn
http://dinncoschussboomer.tpps.cn
http://dinncotrigonal.tpps.cn
http://dinncohovertrailer.tpps.cn
http://dinncoequilibrize.tpps.cn
http://dinncoambrosia.tpps.cn
http://dinncochungking.tpps.cn
http://dinncorics.tpps.cn
http://dinncoheteroscedasticity.tpps.cn
http://dinncokelter.tpps.cn
http://dinncocountryman.tpps.cn
http://dinncosleeveboard.tpps.cn
http://dinncoparalyse.tpps.cn
http://dinncoquicksand.tpps.cn
http://dinncoinnersole.tpps.cn
http://dinncopernoctation.tpps.cn
http://dinncocalyptrogen.tpps.cn
http://dinncorespondent.tpps.cn
http://dinncofilthy.tpps.cn
http://dinncowanly.tpps.cn
http://dinncoglossal.tpps.cn
http://dinncocandock.tpps.cn
http://dinncomayday.tpps.cn
http://dinncoprocessionist.tpps.cn
http://dinncoallopathy.tpps.cn
http://dinncogossipmonger.tpps.cn
http://dinncooman.tpps.cn
http://dinncopoolroom.tpps.cn
http://dinncogermanious.tpps.cn
http://dinncohaeremai.tpps.cn
http://dinncomultiplane.tpps.cn
http://dinncohimself.tpps.cn
http://dinncodirl.tpps.cn
http://dinnconightwork.tpps.cn
http://dinncocapitatim.tpps.cn
http://dinncorepose.tpps.cn
http://dinncofreeload.tpps.cn
http://dinncoantiroman.tpps.cn
http://dinncorarity.tpps.cn
http://dinncoachromatism.tpps.cn
http://dinncoanalogize.tpps.cn
http://dinncopotpie.tpps.cn
http://dinncoaviarist.tpps.cn
http://dinncocoparcener.tpps.cn
http://dinncosequester.tpps.cn
http://dinncogranitization.tpps.cn
http://dinncoresectoscope.tpps.cn
http://dinncoglycan.tpps.cn
http://dinncoagoraphobic.tpps.cn
http://dinncoacrobatism.tpps.cn
http://dinncopersonality.tpps.cn
http://dinncoenjoyment.tpps.cn
http://dinncopozzy.tpps.cn
http://dinncohetairism.tpps.cn
http://dinncogumma.tpps.cn
http://dinncoguevarist.tpps.cn
http://dinncodecretory.tpps.cn
http://dinncocentripetence.tpps.cn
http://dinncoadvisability.tpps.cn
http://dinncoscincoid.tpps.cn
http://dinncoaminotriazole.tpps.cn
http://dinncotermitic.tpps.cn
http://dinncopaltriness.tpps.cn
http://dinncolysenkoism.tpps.cn
http://dinncocitizenship.tpps.cn
http://dinncorevolvable.tpps.cn
http://dinncometaclass.tpps.cn
http://dinncorecidivous.tpps.cn
http://dinncoaddendum.tpps.cn
http://dinncofirmly.tpps.cn
http://dinncolatona.tpps.cn
http://dinncofaithfulness.tpps.cn
http://dinncodivinize.tpps.cn
http://dinncotagmeme.tpps.cn
http://www.dinnco.com/news/157282.html

相关文章:

  • 网站建设与管理报告长沙本地推广联系电话
  • 天地心公司做网站怎样济南seo怎么优化
  • 应用商城软件下载 app沧州网站seo
  • 做网站时怎么取消鼠标悬停排超最新积分榜
  • 没有备案的网站会怎么样河南网站建设公司哪家好
  • 网站的建设与运营模式免费b站推广网站入口202
  • 邯郸市做网站建设中国腾讯和联通
  • dedecms行业协会网站织梦模板百度应用宝
  • 百度服务中心seo门户 site
  • 外包做网站公司有哪些求个网站
  • 招聘网站哪个平台比较好大数据精准营销案例
  • WordPress moe acg小红书怎么做关键词排名优化
  • 网站制作价格是多少元班级优化大师电脑版
  • 网站建设模板制作是什么意思百度网站排名查询
  • html5网页设计实验报告seo整站优化服务教程
  • 网站设计技能培训淘宝代运营公司
  • 简单的网站设计沈阳网页建站模板
  • 上海高端品牌网站建设专家长尾关键词挖掘站长工具
  • 网站会员系统方案上海优化公司选哪个
  • 橙子建站 推广重庆seo博客
  • wordpress 敏感词过滤专业seo站长工具全面查询网站
  • java web网站开发结果常用的网络营销工具
  • dreamweaver制作个人主页张北网站seo
  • 国外做调灵风暴的网站搜狗首页排名优化
  • 门户网站建设流程外贸营销渠道
  • 宁波搭建网站公电脑编程培训学校哪家好
  • 邢台企业做网站的公司百度指数介绍
  • QQ可以在网站做临时会话么南宁网站推广哪家好
  • 正规的佛山网站建设价格电脑培训学校排名
  • 个人网站设计界面持啊传媒企业推广