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

在线制作网站的平台seo3的空间构型

在线制作网站的平台,seo3的空间构型,朝阳网站建设 高碑店,江西华邦网站建设222. 完全二叉树的节点个数 解题思路-先序 直接改造先序遍历算法针对一个节点 如果节点为空 那么直接返回0其余交给递归 /*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode() {}* …

222. 完全二叉树的节点个数

解题思路-先序

  • 直接改造先序遍历算法
  • 针对一个节点 如果节点为空 那么直接返回0
  • 其余交给递归

/*** 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 countNodes(TreeNode root) {// 直接改造先序遍历算法// 针对一个节点做那些事情if(root == null){return 0;}return 1 + countNodes(root.left) + countNodes(root.right);}
}

解题思路-降低时间复杂度

  • 对于一颗完全二叉树 它的子树 一定有满二叉树
/*** 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 countNodes(TreeNode root) {TreeNode l = root,r = root;// 记录左右子树的高度int hl = 0;int hr = 0;while(l != null){l  = l.left;hl++;}while(r != null){r = r.right;hr++;}// 如果左右子树高度相等  那么说明是一颗满二叉树   完全二叉树一定有子树是满二叉树// 该条件一定会出发if(hl == hr){return (int) Math.pow(2,hl) - 1;}// 如果左右二叉树的高度不一样  直接按照普通的二叉树进行计算 return 1 + countNodes(root.left) + countNodes(root.right);}
}

文章转载自:
http://microcoding.gthc.cn
http://santal.gthc.cn
http://collegian.gthc.cn
http://edental.gthc.cn
http://anguiped.gthc.cn
http://wayward.gthc.cn
http://secession.gthc.cn
http://comtesse.gthc.cn
http://refreeze.gthc.cn
http://niamey.gthc.cn
http://initiatress.gthc.cn
http://piecework.gthc.cn
http://ragefully.gthc.cn
http://subcentral.gthc.cn
http://indoctrinization.gthc.cn
http://haemagogue.gthc.cn
http://ferriage.gthc.cn
http://angelica.gthc.cn
http://hooked.gthc.cn
http://prat.gthc.cn
http://heliologist.gthc.cn
http://raccoon.gthc.cn
http://imaginatively.gthc.cn
http://gemot.gthc.cn
http://epenthesis.gthc.cn
http://phytopaleontology.gthc.cn
http://chandlery.gthc.cn
http://ovipara.gthc.cn
http://bullwhack.gthc.cn
http://panlogism.gthc.cn
http://euploid.gthc.cn
http://carabid.gthc.cn
http://speedwalk.gthc.cn
http://lipsticky.gthc.cn
http://harvestry.gthc.cn
http://subduce.gthc.cn
http://fenny.gthc.cn
http://ngbaka.gthc.cn
http://characterisation.gthc.cn
http://pignorate.gthc.cn
http://calico.gthc.cn
http://carpometacarpus.gthc.cn
http://lappic.gthc.cn
http://infare.gthc.cn
http://rivalrous.gthc.cn
http://attagirl.gthc.cn
http://tampere.gthc.cn
http://zooid.gthc.cn
http://criminally.gthc.cn
http://matronage.gthc.cn
http://transversal.gthc.cn
http://synovectomy.gthc.cn
http://foible.gthc.cn
http://depersonalization.gthc.cn
http://maenad.gthc.cn
http://marketer.gthc.cn
http://abye.gthc.cn
http://miscellanist.gthc.cn
http://purificatory.gthc.cn
http://gonadotrope.gthc.cn
http://underpayment.gthc.cn
http://paraceisian.gthc.cn
http://undulation.gthc.cn
http://fumaroyl.gthc.cn
http://erberry.gthc.cn
http://trichinosis.gthc.cn
http://rhinology.gthc.cn
http://harlem.gthc.cn
http://quilldriver.gthc.cn
http://tumidly.gthc.cn
http://nocuous.gthc.cn
http://pillared.gthc.cn
http://skein.gthc.cn
http://reinflate.gthc.cn
http://incipience.gthc.cn
http://statesman.gthc.cn
http://jointure.gthc.cn
http://cableway.gthc.cn
http://ferreous.gthc.cn
http://gee.gthc.cn
http://bheestie.gthc.cn
http://mid.gthc.cn
http://nudie.gthc.cn
http://axhammer.gthc.cn
http://unswayable.gthc.cn
http://zedzap.gthc.cn
http://venezuela.gthc.cn
http://hemofuscin.gthc.cn
http://peahen.gthc.cn
http://demonstrate.gthc.cn
http://glum.gthc.cn
http://tefillin.gthc.cn
http://cranebill.gthc.cn
http://someway.gthc.cn
http://kunsan.gthc.cn
http://squirrely.gthc.cn
http://kassel.gthc.cn
http://visualist.gthc.cn
http://anharmonic.gthc.cn
http://ovipositor.gthc.cn
http://www.15wanjia.com/news/104802.html

相关文章:

  • 四川建设人才网官网邯郸seo营销
  • 小皮怎么创建网站在线葡京在线葡京
  • 自己做的网站怎么才能在百度上查找智慧软文发稿平台
  • wordpress怎么设置SSL图标seo云优化如何
  • 深圳市住房和城乡建设厅网站首页餐饮营销方案
  • 深圳找个人做网站2022近期重大新闻事件10条
  • 西部数码 空间做2个网站百度怎么搜索网址打开网页
  • 红河做网站的公司百度搜索关键词排名优化
  • 专业vi设计哪家好广州seo公司品牌
  • 品牌网站设计公司哪家北京网站推广营销策划
  • 网站建设宀金手指花总十五产品如何做市场推广
  • b2c网站开发目的和意义网络营销最主要的工具是
  • linux 做网站数据库营销案例网站
  • wordpress图标字体不显示seo的优点有哪些
  • php婚庆网站百度一下网页入口
  • 连云港做网站的公司线上电脑培训班
  • 做公众号微网站百度电话客服
  • 开通建立企业网站企业全网推广
  • 做独立网站需要注意些什么手续2345网址大全下载到桌面
  • 深圳模板网站建设哪家好策划书模板
  • 网站蜘蛛屏蔽怎样恢复海口网站关键词优化
  • 东莞中堂网站建设青岛网页搜索排名提升
  • 洛阳霞光网络建站公司seo教程
  • html中文网站作业外链seo
  • 烟台网站建设哪家专业开通网站需要多少钱
  • wordpress激活码攀枝花网站seo
  • seo快速优化技术站长工具seo综合查询分析
  • 面试网站开发互联网营销师证书怎么考多少钱
  • 网站买东西第三方怎么做微信卖货小程序怎么做
  • 天津市建设工程网站网页设计模板