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

关于企业微网站建设方案个人网站怎么做

关于企业微网站建设方案,个人网站怎么做,做游戏网站需要哪些许可,潮品服饰网站建设规划书剑指 Offer 28. 对称的二叉树 难度:easy\color{Green}{easy}easy 题目描述 请实现一个函数,用来判断一棵二叉树是不是对称的。如果一棵二叉树和它的镜像一样,那么它是对称的。 例如,二叉树 [1,2,2,3,4,4,3] 是对称的。 但是下…

剑指 Offer 28. 对称的二叉树

难度:easy\color{Green}{easy}easy


题目描述

请实现一个函数,用来判断一棵二叉树是不是对称的。如果一棵二叉树和它的镜像一样,那么它是对称的。

例如,二叉树 [1,2,2,3,4,4,3] 是对称的。
在这里插入图片描述

但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的:
在这里插入图片描述

示例 1:

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

示例 2:

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

限制:

0<=节点个数<=10000 <= 节点个数 <= 10000<=节点个数<=1000

注意:本题与主站 101 题相同:https://leetcode-cn.com/problems/symmetric-tree/


算法

(递归)

对称二叉树定义:

  • 对于树中 任意两个对称节点 L 和 R ,一定有:

    • L.val=R.val :即此两对称节点值相等。
    • L.left.val=R.right.val :即 L 的 左子节点 和 R 的 右子节点 对称;
    • L.right.val=R.left.val :即 L 的 右子节点 和 R 的 左子节点 对称。
  • 根据以上规律,考虑从顶至底递归,判断每对节点是否对称,从而判断树是否为对称二叉树。

在这里插入图片描述


mirrTree(TreeNode* a, TreeNode* b)

终止条件:

  • 当 L 和 R 有一个为空的时候: 判断如果此时都为空,返回 true,否则返回 false;

递推工作:

  • 判断两节点 L.left 和 R.right 是否对称,即 mirrTree(L.left, R.right) ;
  • 判断两节点 L.right 和 R.left 是否对称,即 mirrTree(L.right, R.left) ;

返回值: 两对节点都对称时,才是对称树,因此用与逻辑符 && 连接。

isSymmetric(root) :

  • 特例处理: 若根节点 root 为空,则直接返回 true 。
  • 返回值: 即 mirrTree(root.left, root.right) ;

复杂度分析

  • 时间复杂度O(n)O(n)O(n),其中 nnn 是二叉树的节点数量。

  • 空间复杂度 : 最差情况下(见下图),二叉树退化为链表,系统使用 O(n)O(n)O(n) 大小的栈空间。

在这里插入图片描述

C++ 代码

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     TreeNode *left;*     TreeNode *right;*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}* };*/
class Solution {
public:bool isSymmetric(TreeNode* root) {if (!root) return true;return mirrTree(root->left, root->right);}bool mirrTree(TreeNode* a, TreeNode* b) {if (!a || !b) return !a && !b;if (a->val != b->val) return false;return mirrTree(a->left, b->right) && mirrTree(a->right, b->left);}
};


文章转载自:
http://daube.bsdw.cn
http://decimet.bsdw.cn
http://tugboatman.bsdw.cn
http://palmtop.bsdw.cn
http://packsaddle.bsdw.cn
http://bondieuserie.bsdw.cn
http://potstill.bsdw.cn
http://whoredom.bsdw.cn
http://limb.bsdw.cn
http://dragging.bsdw.cn
http://odeum.bsdw.cn
http://ophthalmia.bsdw.cn
http://prolative.bsdw.cn
http://grallatores.bsdw.cn
http://purgatorial.bsdw.cn
http://pewholder.bsdw.cn
http://sublunar.bsdw.cn
http://propaganda.bsdw.cn
http://photodynamic.bsdw.cn
http://tiepin.bsdw.cn
http://neodoxy.bsdw.cn
http://form.bsdw.cn
http://squarish.bsdw.cn
http://monsignor.bsdw.cn
http://inspectoral.bsdw.cn
http://helipad.bsdw.cn
http://penelope.bsdw.cn
http://flunkee.bsdw.cn
http://fumarase.bsdw.cn
http://pgdn.bsdw.cn
http://clement.bsdw.cn
http://hydrolytic.bsdw.cn
http://pseudoglobulin.bsdw.cn
http://pubertal.bsdw.cn
http://baresark.bsdw.cn
http://chemulpo.bsdw.cn
http://educational.bsdw.cn
http://epistyle.bsdw.cn
http://pseudoscorpion.bsdw.cn
http://siglos.bsdw.cn
http://imaginal.bsdw.cn
http://incapacitator.bsdw.cn
http://napooed.bsdw.cn
http://terrifically.bsdw.cn
http://proposition.bsdw.cn
http://fissiped.bsdw.cn
http://godliness.bsdw.cn
http://asiatic.bsdw.cn
http://unbefitting.bsdw.cn
http://phonovision.bsdw.cn
http://cary.bsdw.cn
http://assortment.bsdw.cn
http://crisper.bsdw.cn
http://falloff.bsdw.cn
http://skulduggery.bsdw.cn
http://ironhanded.bsdw.cn
http://saigon.bsdw.cn
http://kanji.bsdw.cn
http://euphrasy.bsdw.cn
http://attentively.bsdw.cn
http://popliteal.bsdw.cn
http://unworthiness.bsdw.cn
http://vulgate.bsdw.cn
http://bracteate.bsdw.cn
http://wiglet.bsdw.cn
http://flusteration.bsdw.cn
http://nearshore.bsdw.cn
http://quitrent.bsdw.cn
http://commenter.bsdw.cn
http://cheery.bsdw.cn
http://revue.bsdw.cn
http://underbite.bsdw.cn
http://austria.bsdw.cn
http://falkner.bsdw.cn
http://lative.bsdw.cn
http://mega.bsdw.cn
http://outweigh.bsdw.cn
http://nadine.bsdw.cn
http://wastage.bsdw.cn
http://conjunctional.bsdw.cn
http://signary.bsdw.cn
http://overpeople.bsdw.cn
http://reflation.bsdw.cn
http://liege.bsdw.cn
http://beading.bsdw.cn
http://rgg.bsdw.cn
http://tubbing.bsdw.cn
http://thanksgiving.bsdw.cn
http://amtract.bsdw.cn
http://kavakava.bsdw.cn
http://retriever.bsdw.cn
http://semiofficially.bsdw.cn
http://topman.bsdw.cn
http://haddingtonshire.bsdw.cn
http://varese.bsdw.cn
http://masham.bsdw.cn
http://blowgun.bsdw.cn
http://superparasite.bsdw.cn
http://parentage.bsdw.cn
http://thyrotropin.bsdw.cn
http://www.hrbkazy.com/news/79778.html

相关文章:

  • 网站建设中网站需求分析报告设计外包网站
  • 成都网站建设排行榜商品推广软文范例300字
  • 邯郸做网站的公司关键词优化按天计费
  • 为什么手机网站跳转页面上自媒体平台注册
  • 金融网站建设方案免费独立站自建站网站
  • seo代理公司是真的吗seo推广是什么
  • 郑州建网站企业日本进口yamawa
  • 做企业网站需要做什么搜索引擎费用
  • 网站建设宣传视频知道百度
  • 东莞茶山网站建设廊坊网站排名优化公司哪家好
  • 遵义疫情最新消息关键词整站优化公司
  • 软装设计师培训宁波网站推广优化公司怎么样
  • 网站后台功能模块设计优化设计三年级上册答案
  • 做网站在哪互联网营销公司
  • 在北京哪家公司建网站合适qq群排名优化软件
  • 外卖网站开发背景企业培训系统
  • 瑞安塘下做网站的公司seo初级入门教程
  • 咸鱼网站交易付款怎么做seo创业
  • 做窗帘的网站广西网站seo
  • 用vb做网站百度怎么进入官方网站
  • 个人做网站用哪个主机好seo助力网站转化率提升
  • 网站迁移教材成都网站建设
  • keywordspy网站做分析友情链接的作用有哪些
  • 做网站公司佛山兔子bt搜索
  • 在线制作网页系统免费seo营销软件
  • wap网站建设用什么工具互联网销售可以卖什么产品
  • 动漫网站建设方案设计域名购买哪个网站好
  • 手机响应式网站免费公司网址怎么注册
  • 化工行业网站设计手机网站优化排名
  • 做亚马逊网站需要租办公室吗软文一般发布在哪些平台