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

哪个网站是专门做装修的选择网站设计公司佛山

哪个网站是专门做装修的,选择网站设计公司佛山,建网站空间可以不买,网页无法访问此页面1.前言 http://t.csdnimg.cn/lO4S7 在前文我们已经简单的讲解了二叉树的基本概念#xff0c;本文将讲解具体的实现 2.基本功能的实现 2.1获取树中节点个数 public int size(TreeNode root){if(rootnull){return 0;}int retsize(root.left)size(root.right)1;return ret;}p…1.前言 http://t.csdnimg.cn/lO4S7 在前文我们已经简单的讲解了二叉树的基本概念本文将讲解具体的实现 2.基本功能的实现 2.1获取树中节点个数 public int size(TreeNode root){if(rootnull){return 0;}int retsize(root.left)size(root.right)1;return ret;}public static int nodeSize;public void size2(TreeNode root){if(rootnull){return;}nodeSize;size2(root.left);size2(root.right);} 2.2获取叶子节点的个数 /*** 求叶子节点个数* param root* return*/public int getLeafNodeCount(TreeNode root){if(rootnull){return 0;}if(root.leftnullroot.rightnull){return 1;}return getLeafNodeCount(root.left)getLeafNodeCount(root.right);}public int leftSize;public void getLeafNodeCount2(TreeNode root){if(rootnull){return;}if(root.leftnullroot.rightnull){leftSize;}getLeafNodeCount2(root.left);getLeafNodeCount2(root.right);} 2.3获取第K层节点的个数 /*第k层有几个节点*/public int getKLevelNodeCount(TreeNode root,int k){if(rootnull){return 0;}if(k1){return 1;}return getKLevelNodeCount(root.left,k-1)getKLevelNodeCount(root.right,k-1);} 2.4获取二叉树的高度 public int getHeight(TreeNode root){if(rootnull){return 0;}int leftHeightgetHeight(root.left);int rightHeightgetHeight(root.right);return leftHeightrightHeight?leftHeight1:rightHeight1;} 2.5检测值为value的元素是否存在 /**** param root* param val* return*/public TreeNode find(TreeNode root,char val){if(rootnull){return null;}if(root.valval){return root;}TreeNode retfind(root.left,val);if(ret!null){return ret;}retfind(root.right,val);if(ret!null){return ret;}return null;} 2.6判断一棵树是不是完全二叉树 public boolean isSameTree(TreeNode p,TreeNode q){if(p!nullqnull||pnullq!null){return false;}if(pnullqnull){return true;}if(p.val!q.val){return false;}return isSameTree(p.left,q.left)isSameTree(p.right,q.right);} 3.二叉树的应用  在知晓了二叉树相关功能的底层实现之后我们应用二叉树知识来解答 3.1二叉树遍历 二叉树遍历_牛客题霸_牛客网   根据题目我们可以知道这其实是两个题目一是创建二叉树二是中序遍历结果 所以我们分成两部来完成 先定义二叉树的结构 class TreeNode {public char val;public TreeNode left;public TreeNode right;public TreeNode(char val) {this.val val;}} 当不为#的时候我们就创建节点 public static int i 0;public static TreeNode createTree(String str) {TreeNode root null;if (str.charAt(i) ! #) {root new TreeNode(str.charAt(i));i;root.left createTree(str);root.right createTree(str);} else {i;}return root;} 最后我们进行中序遍历——根左子树-根节点-根右子树的顺序来递归即可  public static void inorder(TreeNode root){if(rootnull){return;}inorder(root.left);System.out.print(root.val );inorder(root.right);} 3.2二叉树的层序遍历 . - 力扣LeetCode 这题主要是对二叉树的层序遍历对于层序遍历是如何遍历的我们在上文已经讲过——从上而下自左向右依次遍历. 在了解到概念之后我们就可以进行解答了 我们要对知识进行灵活的应用这种从上而下自左向右的逻辑与前面所讲到的栈和队列知识中队列先进先出逻辑类似所以我们可以用创建队列来解答 1.是否为空若为空则返回空列表 2.若不为空则进入循环判断当队列为空则跳出循环创建一个列表来打印每层的结果 3.将每层结果存入ret,最后返回ret即可 /*** 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 ListListInteger levelOrder(TreeNode root) {ListListInteger retnew ArrayList();if(rootnull){return ret;}QueueTreeNode queue new LinkedList();queue.offer(root);while(!queue.isEmpty()){int sizequeue.size();ListInteger listnew ArrayList();//每层while(size0){TreeNode curqueue.poll();list.add(cur.val);if(cur.left!null){queue.offer(cur.left);}if(cur.right!null){queue.offer(cur.right);}size--;}ret.add(list);}return ret;} } 对二叉树的基础知识讲解就到这里如果上述内容对您有帮助希望给个三连谢谢
http://www.w-s-a.com/news/949496/

相关文章:

  • 广东网站开发推荐网页制作个人简历模板教程
  • e建网保定百度seo公司
  • 网站建设中html代码网络培训课堂app
  • 无锡做网站seo自己做的网站如何上传网上
  • 园林景观网站模板小白怎么做跨境电商
  • 找第三方做网站 需要注意企业网站带数据库
  • 北京南站到北京站flash网站制作单选框和复选框ui组件
  • 网站建设核电集团网站设计案例
  • 宝塔做的网站能不能访问上海的广告公司网站建设
  • 网站会员系统方案新能源网站建设哪家好
  • 全球网站域名域名被墙查询
  • 做期货看资讯什么网站好哈尔滨网站设计联系方式
  • 建站宝盒免费下载上海网论坛网址
  • 国内最有趣的25个网站推广流程
  • 红河做网站抖音小程序怎么挂到抖音上
  • 高度重视机关门户网站建设外包
  • 网站里面送礼物要钱怎么做代码网站开发怎么对接客户
  • 泰州网站制作策划如何做网站需求
  • 门户网站优化报价软件技术公司
  • 怎样换网站logo公司名字大全集免费
  • 为网站网站做推广各类最牛网站建设
  • 网站用自己的电脑做服务器佛山做网站制作公司
  • 一个网站如何做cdn加速器如何上传网站数据库
  • 汝州住房和城乡建设局新网站营销网站定位
  • yy直播官网seo引擎优化是什
  • 做影视网站违法莫品牌营销是什么
  • 全网最稳最低价自助下单网站wordpress电影网站主题
  • 域名更换网站温州建设工程网站
  • 网站如何优化推广连锁店管理网站开发
  • 伊宁市做网站功能性质网站