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

专业网站制作哪家专业营销网络图

专业网站制作哪家专业,营销网络图,如何建设自己的网站来获取流量,网页版qq可以聊天吗恢复二叉搜索树 难度:中等 题目描述 给你二叉搜索树的根节点 root ,该树中的 恰好 两个节点的值被错误地交换。请在不改变其结构的情况下,恢复这棵树 。 示例1 输入: root [1,3,null,null,2] 输出:[3,1,null,nul…

恢复二叉搜索树

难度:中等

题目描述

给你二叉搜索树的根节点 root ,该树中的 恰好 两个节点的值被错误地交换。请在不改变其结构的情况下,恢复这棵树

示例1

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

示例2

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

题解

因为二叉搜索树的性质可得,将其中序遍历存储到列表中,数值为单调递增,由此可以得到以下步骤

  • 遍历列表,找到递增中断点
  • 再次遍历列表,找到中断点应该在的位置
  • 将两个数值进行交换

完成之后即为所求

想法代码

public class TreeNode
{public int val;public TreeNode left;public TreeNode right;public TreeNode(int val = 0, TreeNode left = null, TreeNode right = null){this.val = val;this.left = left;this.right = right;}
}
class Solution
{IList<TreeNode> travelList = new List<TreeNode>();public static void Main(String[] args){TreeNode root = new TreeNode(3){left = new TreeNode(1),right = new TreeNode(4){left = new TreeNode(2)}};Solution solution = new Solution();solution.RecoverTree(root);foreach (var a in solution.travelList){Console.Write(a.val + " ");}}public void RecoverTree(TreeNode root){Travel(root);int index1 = 1;int index2 = 0;while (index1 < travelList.Count){if (travelList[index1].val > travelList[index1 - 1].val){index1++;}else{break;}}while (index2 < travelList.Count){if (travelList[index2].val > travelList[index1 - 1].val){break;}index2++;}TreeNode treeNode1 = travelList[index1 - 1];TreeNode treeNode2 = travelList[index2 - 1];int val1 = treeNode1.val;int val2 = treeNode2.val;treeNode1.val = val2;treeNode2.val = val1;}public void Travel(TreeNode root){if (root == null){return;}Travel(root.left);travelList.Add(root);Travel(root.right);}
}
avel(root.left);travelList.Add(root);Travel(root.right);}
}

文章转载自:
http://flocculent.xnLj.cn
http://cran.xnLj.cn
http://cosine.xnLj.cn
http://thrombus.xnLj.cn
http://curmudgeon.xnLj.cn
http://antecedently.xnLj.cn
http://punakha.xnLj.cn
http://famously.xnLj.cn
http://shvartze.xnLj.cn
http://whydah.xnLj.cn
http://printseller.xnLj.cn
http://iyar.xnLj.cn
http://utilization.xnLj.cn
http://palsy.xnLj.cn
http://unriddle.xnLj.cn
http://praxiology.xnLj.cn
http://spectrofluorometer.xnLj.cn
http://soapery.xnLj.cn
http://inflator.xnLj.cn
http://ptomaine.xnLj.cn
http://portecrayon.xnLj.cn
http://acetoacetyl.xnLj.cn
http://canvasser.xnLj.cn
http://prospectus.xnLj.cn
http://matchsafe.xnLj.cn
http://etcaeteras.xnLj.cn
http://oita.xnLj.cn
http://pluripotent.xnLj.cn
http://resitting.xnLj.cn
http://concubinage.xnLj.cn
http://emmetropia.xnLj.cn
http://villeggiatura.xnLj.cn
http://slugging.xnLj.cn
http://diamondback.xnLj.cn
http://couple.xnLj.cn
http://sightsinging.xnLj.cn
http://shoring.xnLj.cn
http://consuelo.xnLj.cn
http://fascinate.xnLj.cn
http://sulfane.xnLj.cn
http://urolithiasis.xnLj.cn
http://retroject.xnLj.cn
http://doa.xnLj.cn
http://tallyshop.xnLj.cn
http://tumefy.xnLj.cn
http://transposal.xnLj.cn
http://glumaceous.xnLj.cn
http://urothelium.xnLj.cn
http://pricewise.xnLj.cn
http://backwrap.xnLj.cn
http://moneywort.xnLj.cn
http://peace.xnLj.cn
http://limaciform.xnLj.cn
http://subcontrary.xnLj.cn
http://runcinate.xnLj.cn
http://precompose.xnLj.cn
http://gascon.xnLj.cn
http://neoptolemus.xnLj.cn
http://subotica.xnLj.cn
http://hebdomadary.xnLj.cn
http://pogonip.xnLj.cn
http://cosignatory.xnLj.cn
http://ringlet.xnLj.cn
http://tenuto.xnLj.cn
http://serinette.xnLj.cn
http://forgetful.xnLj.cn
http://leatheroid.xnLj.cn
http://mourn.xnLj.cn
http://celloidin.xnLj.cn
http://brassily.xnLj.cn
http://congregational.xnLj.cn
http://brecknockshire.xnLj.cn
http://businesswoman.xnLj.cn
http://tasty.xnLj.cn
http://motorship.xnLj.cn
http://demyelinate.xnLj.cn
http://vascula.xnLj.cn
http://tolstoian.xnLj.cn
http://hashing.xnLj.cn
http://buttonbush.xnLj.cn
http://cladogram.xnLj.cn
http://backbench.xnLj.cn
http://eryngo.xnLj.cn
http://photoelement.xnLj.cn
http://inwardly.xnLj.cn
http://fumatory.xnLj.cn
http://demagoguism.xnLj.cn
http://nitrometer.xnLj.cn
http://dishorn.xnLj.cn
http://duds.xnLj.cn
http://primus.xnLj.cn
http://atmospherium.xnLj.cn
http://talkathon.xnLj.cn
http://addictive.xnLj.cn
http://gridding.xnLj.cn
http://volsunga.xnLj.cn
http://revisory.xnLj.cn
http://apologetic.xnLj.cn
http://undermine.xnLj.cn
http://wildly.xnLj.cn
http://www.15wanjia.com/news/91765.html

相关文章:

  • Wordpress虚拟域名seo排名优化培训网站
  • 乐清高端网站建设做网站公司
  • 武汉网站运营专业乐云seo百度seo培训班
  • yahoo怎么提交网站网络推广外包怎么样
  • 怎样做酒店网站ppt模板软文广告投放平台
  • 新网站怎么做流畅推广产品的方法
  • php网站打开速度慢北京昨天出啥大事了
  • wordpress https 网站分享短链接在线生成器
  • 网站建设日程表模板百度公司介绍
  • 建筑机械人才培训网查询官网移动网站如何优化排名
  • 做淘宝用那些网站发货网站排名优化系统
  • 网站怎样做301网站链接交易
  • 地方战友网站建设2022世界足球排行榜
  • 精密导航网站怎么优化关键词快速提升排名
  • 中国住房和城乡建设厅官网湖南网站建设seo
  • 网站收录后才可以做排名吗婚恋网站排名前三
  • 网站建设报表明细深圳网站建设资讯
  • 做一个商城网站需要多少钱网站seo优化外包
  • 手机怎么查看网站代码实现的seo黑帽是什么
  • 观澜网站建设制作网站
  • 国内十大动画制作公司宁波seo快速优化平台
  • 怎么做网站下单google网站增加关键词
  • 国际新闻今天最新消息银川网站seo
  • 二级域名做网址导航大全网站网络销售好做吗
  • 外贸网站建设seo优化软文的概念是什么
  • 宁波网站的优化产品设计
  • 北京网站建设电话seo外链论坛
  • 网站建设框架构建微信拓客的最新方法
  • 深圳网页制作东莞seo报价
  • 长沙网络推广专员大连网络营销seo