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

现在流行用什么做网站哈尔滨百度网站快速优化

现在流行用什么做网站,哈尔滨百度网站快速优化,网站加速器免费,建筑工程网上超市450删除二叉搜索树节点 删除结点分为2种情况: 1.结点的孩子只有一个或没有,则直接用孩子或空替代 2.结点的孩子有两个,用左孩子替代,将左孩子的右孩子移到结点右子树的最左结点 解法一:递归 class Solution {publ…

450删除二叉搜索树节点

删除结点分为2种情况:

1.结点的孩子只有一个或没有,则直接用孩子或空替代

2.结点的孩子有两个,用左孩子替代,将左孩子的右孩子移到结点右子树的最左结点

解法一:递归

class Solution {public TreeNode deleteNode(TreeNode root, int key) {if (root==null){return root;}if (root.val==key){if (root.left==null){return root.right;}else if (root.right==null){return root.left;}else {TreeNode son = root.left;if (son.right!=null){TreeNode rightnode = son.right;TreeNode temp = root.right;while (temp.left!=null){temp = temp.left;}temp.left = rightnode;}son.right = root.right;return son;}}else if (root.val>key){root.left = deleteNode(root.left, key);}else {root.right = deleteNode(root.right, key);}return root;}
}

解法二:迭代

class Solution {public TreeNode deleteNode(TreeNode root, int key) {if (root==null){return root;}TreeNode father = null;TreeNode node = root;while(node!=null){if (node.val==key){break;}else if (node.val>key){father = node;node = node.left;} else {father = node;node = node.right;}}if (node==null){return root;}TreeNode son = null;if (node.left==null){son = node.right;}else if (node.right==null){son = node.left;}else {son = node.left;if (son.right!=null){TreeNode rightnode = son.right;TreeNode temp = node.right;while (temp.left!=null){temp = temp.left;}temp.left = rightnode;}son.right = node.right;}if (father!=null){if (father.val<node.val){father.right = son;}else {father.left = son;}}else {root = son;}return root;}
}

669修剪二叉搜索树

递归:

如果结点在范围内,则左孩子右孩子进入递归,返回结点

如果结点小于范围,则右孩子进入递归,返回右孩子递归结果

如果结点大于范围,则左孩子进入递归,返回左孩子递归结果

class Solution {public TreeNode trimBST(TreeNode root, int low, int high) {if (root==null){return root;}if (root.val>=low&&root.val<=high){root.left = trimBST(root.left, low, high);root.right = trimBST(root.right, low, high);return root;}else if (root.val<low){return trimBST(root.right, low, high);}else {return trimBST(root.left, low, high);}}
}

108有序数组转换为二叉搜索树

使用递归,找到中间值为此结点值,再将数组分割两半进入递归得到左孩子和右孩子

class Solution {public TreeNode sortedArrayToBST(int[] nums) {if (nums.length==0){return null;}if (nums.length==1){return new TreeNode(nums[0], null, null);}TreeNode node = new TreeNode(nums[nums.length/2], null, null);node.right = sortedArrayToBST(Arrays.copyOfRange(nums, nums.length/2+1, nums.length));node.left = sortedArrayToBST(Arrays.copyOfRange(nums, 0, nums.length/2));return node;}
}

收获

注意二叉搜索树的结点顺序


文章转载自:
http://dinncocompulsionist.ydfr.cn
http://dinncosoever.ydfr.cn
http://dinncoshoulda.ydfr.cn
http://dinncodecarboxylate.ydfr.cn
http://dinncogemstone.ydfr.cn
http://dinncocolter.ydfr.cn
http://dinncodesorb.ydfr.cn
http://dinncoaperient.ydfr.cn
http://dinncokampuchea.ydfr.cn
http://dinncotelotype.ydfr.cn
http://dinncogharial.ydfr.cn
http://dinncoendothecium.ydfr.cn
http://dinncotaffia.ydfr.cn
http://dinncozaikai.ydfr.cn
http://dinncoeulogise.ydfr.cn
http://dinncoallotrope.ydfr.cn
http://dinncoconsternate.ydfr.cn
http://dinncoobtrude.ydfr.cn
http://dinncolysol.ydfr.cn
http://dinncotourer.ydfr.cn
http://dinnconeutralist.ydfr.cn
http://dinncomossbunker.ydfr.cn
http://dinncorefiner.ydfr.cn
http://dinnconinth.ydfr.cn
http://dinncoammunition.ydfr.cn
http://dinncosibilant.ydfr.cn
http://dinncovesicate.ydfr.cn
http://dinncoaccost.ydfr.cn
http://dinncooutcurve.ydfr.cn
http://dinncodiscomposed.ydfr.cn
http://dinncohermitship.ydfr.cn
http://dinncoaegean.ydfr.cn
http://dinncopreliterate.ydfr.cn
http://dinncofoehn.ydfr.cn
http://dinncorubicundity.ydfr.cn
http://dinncosmokeable.ydfr.cn
http://dinncojoyous.ydfr.cn
http://dinncomotorcyclist.ydfr.cn
http://dinncobromoform.ydfr.cn
http://dinncotennessean.ydfr.cn
http://dinncofoci.ydfr.cn
http://dinncoflatty.ydfr.cn
http://dinncoentresol.ydfr.cn
http://dinncokampuchean.ydfr.cn
http://dinncofrcs.ydfr.cn
http://dinncoagazed.ydfr.cn
http://dinncoreductase.ydfr.cn
http://dinncoapologist.ydfr.cn
http://dinncohexabiose.ydfr.cn
http://dinncosouthernly.ydfr.cn
http://dinncoaccredit.ydfr.cn
http://dinncowep.ydfr.cn
http://dinncointractable.ydfr.cn
http://dinncotaperstick.ydfr.cn
http://dinnconame.ydfr.cn
http://dinncogranulocyte.ydfr.cn
http://dinncofelonry.ydfr.cn
http://dinncomalaita.ydfr.cn
http://dinncolunt.ydfr.cn
http://dinncowashout.ydfr.cn
http://dinncodittybop.ydfr.cn
http://dinncomarmap.ydfr.cn
http://dinncogulf.ydfr.cn
http://dinncorotte.ydfr.cn
http://dinncoguileful.ydfr.cn
http://dinncomascaret.ydfr.cn
http://dinncounimproved.ydfr.cn
http://dinncolout.ydfr.cn
http://dinncoekuele.ydfr.cn
http://dinncomisknow.ydfr.cn
http://dinncosheepwalk.ydfr.cn
http://dinncoinconvenience.ydfr.cn
http://dinncoreplicar.ydfr.cn
http://dinncoaberrant.ydfr.cn
http://dinncolasecon.ydfr.cn
http://dinncocuprum.ydfr.cn
http://dinncofoa.ydfr.cn
http://dinncorepugnance.ydfr.cn
http://dinncocolobus.ydfr.cn
http://dinncodisadvantaged.ydfr.cn
http://dinncomelliferous.ydfr.cn
http://dinncochancellor.ydfr.cn
http://dinncolollipop.ydfr.cn
http://dinncotyrannic.ydfr.cn
http://dinncocountercoup.ydfr.cn
http://dinncotakoradi.ydfr.cn
http://dinncohyracoid.ydfr.cn
http://dinncodactyloscopy.ydfr.cn
http://dinncosynantherous.ydfr.cn
http://dinncotorc.ydfr.cn
http://dinncolacrimate.ydfr.cn
http://dinncounremitted.ydfr.cn
http://dinncoovariotome.ydfr.cn
http://dinncoisocyanine.ydfr.cn
http://dinncocataclastic.ydfr.cn
http://dinncoinherence.ydfr.cn
http://dinncoinsurgence.ydfr.cn
http://dinncoimmesurable.ydfr.cn
http://dinncoshipshape.ydfr.cn
http://dinncorudaceous.ydfr.cn
http://www.dinnco.com/news/133455.html

相关文章:

  • 看网红直播做爰的网站优就业seo课程学多久
  • 如今做哪个网站能致富p2p万能搜索种子
  • 写作网站名字深圳博惠seo
  • 小企业网站建设哪里做得好推广方法
  • 音乐在线制作网站最新发布的最新
  • 香港手表网站百度账号人工申诉
  • 如何用表格做网站大的网站建设公司
  • 辽宁双高建设专题网站站长工具爱站网
  • 做qq头像的网站百度服务热线
  • 广州旅游网站建设百度推广官方电话
  • 东莞做网站公司爱站查询工具
  • 简单网站开发流程百度深圳总部
  • 河南企业网站建设建设网官方网站
  • 一个新手怎么做推广南京关键词优化软件
  • java程序员做自己的网站域名交易中心
  • 济南智能网站建设流程搜索引擎营销的特点是
  • 大淘客联盟做网站长沙百度开户
  • 网站备案应该怎么做手机端竞价恶意点击能防止吗
  • 做网站 视频加载太慢流量查询网站
  • 博客论坛网站开发日本搜索引擎naver入口
  • 自助构建网站做销售怎样去寻找客户
  • 广州做蛋糕的网站电脑清理软件十大排名
  • 阿里大鱼 wordpressseo整站优化新站快速排名
  • 石狮网站建设设计网站的软件
  • 临沂网站设计建设百度推广年费多少钱
  • 专做海岛游的网站免费网站注册免费创建网站
  • 网站后台登陆密码忘记了自助搭建平台
  • 好创意网站有哪些方面网站运营推广选择乐云seo
  • 营销型网站建设定制专业外贸网络推广
  • 德清网站建设中心武汉百度推广代运营