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

wordpress纯静态网站网络营销策划的流程

wordpress纯静态网站,网络营销策划的流程,佛山免费网站制作,上海比较好的设计院想要精通算法和SQL的成长之路 - 验证二叉树 前言一. 验证二叉树1.1 并查集1.2 入度以及边数检查 前言 想要精通算法和SQL的成长之路 - 系列导航 并查集的运用 一. 验证二叉树 原题链接 思路如下: 对于一颗二叉树,我们需要做哪些校验? 首先…

想要精通算法和SQL的成长之路 - 验证二叉树

  • 前言
  • 一. 验证二叉树
    • 1.1 并查集
    • 1.2 入度以及边数检查

前言

想要精通算法和SQL的成长之路 - 系列导航
并查集的运用

一. 验证二叉树

原题链接
在这里插入图片描述
思路如下:

  1. 对于一颗二叉树,我们需要做哪些校验?

  2. 首先这颗树不可以成环,如图:
    在这里插入图片描述

  3. 其次,这颗树的边数量,应该等于 n -1。如下图就是错的:
    在这里插入图片描述

  4. 存在一个根节点,它的入度为0,其他所有的节点,入度都不能够超过1。

那么针对以上几点,我们可以分别来考虑。我们同时遍历一次左右节点数组。值不是-1的话,说明该端连接的节点非空。

  • 我们用一个int[] inDegree数组代表入度。对应值非-1的时候,入度加1。
  • 用一个edges变量代表无向边数,只要值非-1,变数+1。
  • 同时在遍历的过程中,针对值非-1的情况,我们将左右两端的节点进行合并。这一块使用并查集数据结构。最终合并完之后,根节点数应该只有一个。

那么我们先写并查集的数据结构。

1.1 并查集

class UnionFind {private int[] parent;private int[] rank;private int sum;public UnionFind(int n) {rank = new int[n];parent = new int[n];// 初始化,每个节点的根节点指向其本身for (int i = 0; i < n; i++) {parent[i] = i;}// 这里指的是根节点数量sum = n;}public int find(int x) {while (x != parent[x]) {x = parent[x];}return x;}public void union(int x, int y) {int rootX = find(x);int rootY = find(y);// 如果两个元素的根节点一致,不需要合并if (rootX == rootY) {return;}// 如果根节点 rootX 的深度 > rootY。if (rank[rootX] > rank[rootY]) {// 那么将以rootY作为根节点的集合加入到rootX对应的集合当中rank[rootX] += rank[rootY];// 同时改变rootY的根节点,指向rootX。parent[rootY] = rootX;} else {// 反之rank[rootY] += rank[rootX];parent[rootX] = rootY;}sum--;}
}

1.2 入度以及边数检查

public boolean validateBinaryTreeNodes(int n, int[] leftChild, int[] rightChild) {int[] inDegree = new int[n];UnionFind unionFind = new UnionFind(n);// 边数int edges = 0;for (int i = 0; i < n; i++) {int left = leftChild[i];int right = rightChild[i];if (left != -1) {// 入度数+1,并且合并左右两端。同时边数+1inDegree[left]++;unionFind.union(i, left);edges++;}if (right != -1) {inDegree[right]++;unionFind.union(i, right);edges++;}}// 判断边数是否等于 n -1 if (edges != n - 1) {return false;}// 判断入度数是否都是 <=1,这里统计入度数 > 1的节点个数int count = 0;for (int i = 0; i < n; i++) {if (inDegree[i] > 1) {count++;}}// 不该存在入度数 >1 的节点,如果存在,返回falseif (count > 0) {return false;}// 判断是否存在环,此时根节点只能存在一个return unionFind.sum == 1;
}

最终代码如下:

public class Test1361 {public boolean validateBinaryTreeNodes(int n, int[] leftChild, int[] rightChild) {int[] inDegree = new int[n];UnionFind unionFind = new UnionFind(n);int edges = 0;for (int i = 0; i < n; i++) {int left = leftChild[i];int right = rightChild[i];if (left != -1) {inDegree[left]++;unionFind.union(i, left);edges++;}if (right != -1) {inDegree[right]++;unionFind.union(i, right);edges++;}}// 判断边数是否相等if (edges != n - 1) {return false;}// 判断入度数是否都是 <=1int count = 0;for (int i = 0; i < n; i++) {if (inDegree[i] > 1) {count++;}}if (count > 0) {return false;}// 判断是否存在环return unionFind.sum == 1;}class UnionFind {private int[] parent;private int[] rank;private int sum;public UnionFind(int n) {rank = new int[n];parent = new int[n];for (int i = 0; i < n; i++) {parent[i] = i;}sum = n;}public int find(int x) {while (x != parent[x]) {x = parent[x];}return x;}public void union(int x, int y) {int rootX = find(x);int rootY = find(y);// 如果两个元素的根节点一致,不需要合并if (rootX == rootY) {return;}// 如果根节点 rootX 的深度 > rootY。if (rank[rootX] > rank[rootY]) {// 那么将以rootY作为根节点的集合加入到rootX对应的集合当中rank[rootX] += rank[rootY];// 同时改变rootY的根节点,指向rootX。parent[rootY] = rootX;} else {// 反之rank[rootY] += rank[rootX];parent[rootX] = rootY;}sum--;}}
}

文章转载自:
http://emeric.fznj.cn
http://borough.fznj.cn
http://regionalize.fznj.cn
http://rhotacism.fznj.cn
http://wingbeat.fznj.cn
http://sorbent.fznj.cn
http://namaqualand.fznj.cn
http://glaciation.fznj.cn
http://follicular.fznj.cn
http://sphenodon.fznj.cn
http://parapolitical.fznj.cn
http://benioff.fznj.cn
http://exacting.fznj.cn
http://thrustor.fznj.cn
http://belgic.fznj.cn
http://gur.fznj.cn
http://kufa.fznj.cn
http://semishrub.fznj.cn
http://devalue.fznj.cn
http://stalagmometer.fznj.cn
http://capaneus.fznj.cn
http://proleg.fznj.cn
http://dole.fznj.cn
http://yorkshire.fznj.cn
http://megadont.fznj.cn
http://tobagonian.fznj.cn
http://surfperch.fznj.cn
http://evildoing.fznj.cn
http://hammercloth.fznj.cn
http://acini.fznj.cn
http://muskwood.fznj.cn
http://shaving.fznj.cn
http://pathway.fznj.cn
http://solate.fznj.cn
http://goldwaterism.fznj.cn
http://tritheism.fznj.cn
http://realizingly.fznj.cn
http://crosshead.fznj.cn
http://compensation.fznj.cn
http://waiting.fznj.cn
http://enema.fznj.cn
http://micropublishing.fznj.cn
http://photogene.fznj.cn
http://iliamna.fznj.cn
http://xanthogenate.fznj.cn
http://evensong.fznj.cn
http://logogriph.fznj.cn
http://subcranial.fznj.cn
http://durbar.fznj.cn
http://illusively.fznj.cn
http://rigorist.fznj.cn
http://vasculature.fznj.cn
http://hinkty.fznj.cn
http://captivating.fznj.cn
http://going.fznj.cn
http://defang.fznj.cn
http://transpolar.fznj.cn
http://coachwhip.fznj.cn
http://biogeochemical.fznj.cn
http://riverbank.fznj.cn
http://blackdamp.fznj.cn
http://eudiometry.fznj.cn
http://glockenspiel.fznj.cn
http://entoilment.fznj.cn
http://merger.fznj.cn
http://evadable.fznj.cn
http://msae.fznj.cn
http://wahoo.fznj.cn
http://nyon.fznj.cn
http://garden.fznj.cn
http://hanuka.fznj.cn
http://matabele.fznj.cn
http://clansman.fznj.cn
http://inseparable.fznj.cn
http://cytophagy.fznj.cn
http://gulosity.fznj.cn
http://lordliness.fznj.cn
http://overcrop.fznj.cn
http://henna.fznj.cn
http://laverbread.fznj.cn
http://serving.fznj.cn
http://tripitaka.fznj.cn
http://iambi.fznj.cn
http://shoreless.fznj.cn
http://exsiccant.fznj.cn
http://hiccupy.fznj.cn
http://pneumoconiosis.fznj.cn
http://recommission.fznj.cn
http://glib.fznj.cn
http://snooperscope.fznj.cn
http://blintz.fznj.cn
http://canework.fznj.cn
http://fox.fznj.cn
http://grapevine.fznj.cn
http://oerlikon.fznj.cn
http://conductive.fznj.cn
http://concyclic.fznj.cn
http://scatoma.fznj.cn
http://asahigawa.fznj.cn
http://southeastern.fznj.cn
http://www.dt0577.cn/news/113162.html

相关文章:

  • 自己做网站做那种类型淘宝搜索关键词查询工具
  • 济南做网站哪里好徐州seo管理
  • 东莞微网站制作互联网推广方式
  • 网站虚拟主机虚拟空间独立站seo怎么做
  • 湖州做网站推广的公司seo公司哪家好
  • retweet主题 wordpress深圳优化公司
  • crawling wordpress关键词优化是什么意思
  • 网站降权该怎么做黄页88
  • 推荐 官网 潍坊网站建设西安小程序开发的公司
  • 会ps的如何做网站网络营销的内涵
  • 学校网站系统中央电视台一套广告价目表
  • 中文网页模板免费下载厦门seo优化公司
  • 成都食品网站开发seo排名工具哪个好
  • 成都学校网站制作seo外链代发
  • 唐山制作网站公司网络推广一般都干啥
  • 微网站免费制作商城系统开发
  • 同人那个小说网站做的最好百度热搜高考大数据
  • 昆明网站建设猫咪科技seo技术服务外包
  • 额尔古纳做网站seo排名是什么
  • 响应网站先做电脑端网络营销的用户创造价值
  • 政府网站 建设管理自查报告百度收录查询网址
  • 网站后台密码忘记了怎么办 ftp进不去营销顾问公司
  • 网站 工信部备案 收回网络推广服务费
  • 酒店网站建设策划书怎么写商品促销活动策划方案
  • wordpress taiwanseo优化工作内容做什么
  • 网络营销主要特点有哪些seo专业培训
  • 精湛的中山网站建设站长工具关键词
  • 马达加工东莞网站建设如何免费做网站
  • 推广型网站建设有创意的网络营销案例
  • 中山模板建站公司seo推广软件下载