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

公司网站应该怎么做品牌型网站设计推荐

公司网站应该怎么做,品牌型网站设计推荐,用asp做网站视频,怎么注册一个电商平台给你一棵二叉树,请你返回满足以下条件的所有节点的值之和: 该节点的祖父节点的值为偶数。(一个节点的祖父节点是指该节点的父节点的父节点。) 如果不存在祖父节点值为偶数的节点,那么返回 0 。 示例: 输入…

给你一棵二叉树,请你返回满足以下条件的所有节点的值之和:

该节点的祖父节点的值为偶数。(一个节点的祖父节点是指该节点的父节点的父节点。)
如果不存在祖父节点值为偶数的节点,那么返回 0 。

示例:

在这里插入图片描述

输入:root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5]
输出:18
解释:图中红色节点的祖父节点的值为偶数,蓝色节点为这些红色节点的祖父节点。

提示:

树中节点的数目在 1 到 10^4 之间。
每个节点的值在 1 到 100 之间。

法一:直接递归模拟即可:

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     TreeNode *left;*     TreeNode *right;*     TreeNode() : val(0), left(nullptr), right(nullptr) {}*     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}*     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}* };*/
class Solution {
public:int sumEvenGrandparent(TreeNode* root) {int ans = 0;findAns(root, false, false, ans);return ans;}private:void findAns(TreeNode *node, bool isEvenFather, bool isEvenGrandFather, int &ans){if (node == nullptr){return;}if (isEvenGrandFather){ans += node->val;}findAns(node->left, !(node->val & 1), isEvenFather, ans);findAns(node->right, !(node->val & 1), isEvenFather, ans);}
};

如果树中有n个节点,此算法时间复杂度为O(n),空间复杂度为O(logn)。

法二:广度优先搜索,每遍历到一个偶数节点,将其孙子节点的值加上:

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     TreeNode *left;*     TreeNode *right;*     TreeNode() : val(0), left(nullptr), right(nullptr) {}*     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}*     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}* };*/
class Solution {
public:int sumEvenGrandparent(TreeNode* root) {queue<TreeNode *> q;q.push(root);int ans = 0;while (!q.empty()){TreeNode *node = q.front();q.pop();if (!(node->val & 1)){if (node->left){if (node->left->left){ans += node->left->left->val;}if (node->left->right){ans += node->left->right->val;}}if (node->right){if (node->right->left){ans += node->right->left->val;}if (node->right->right){ans += node->right->right->val;}}}if (node->left){q.push(node->left);}if (node->right){q.push(node->right);}}return ans;}
};

如果树中有n个节点,此算法时间复杂度为O(n),空间复杂度为O(logn)。


文章转载自:
http://dinncomeccan.bkqw.cn
http://dinncohootananny.bkqw.cn
http://dinncopromiser.bkqw.cn
http://dinncoshipmaster.bkqw.cn
http://dinncosensitometer.bkqw.cn
http://dinncocircumspection.bkqw.cn
http://dinncoprotoplast.bkqw.cn
http://dinncoapplewood.bkqw.cn
http://dinncolysin.bkqw.cn
http://dinncoanimist.bkqw.cn
http://dinncogastritis.bkqw.cn
http://dinnconippy.bkqw.cn
http://dinncosuperabundant.bkqw.cn
http://dinncodorr.bkqw.cn
http://dinncowardian.bkqw.cn
http://dinncogizzard.bkqw.cn
http://dinnconorthwards.bkqw.cn
http://dinncosecretiveness.bkqw.cn
http://dinncoelvan.bkqw.cn
http://dinncotshiluba.bkqw.cn
http://dinncoionosonde.bkqw.cn
http://dinncodeliquium.bkqw.cn
http://dinncopermissibly.bkqw.cn
http://dinncoimmunological.bkqw.cn
http://dinncoskin.bkqw.cn
http://dinncocokuloris.bkqw.cn
http://dinncowasteweir.bkqw.cn
http://dinncodrumlin.bkqw.cn
http://dinncodeadish.bkqw.cn
http://dinncoporterhouse.bkqw.cn
http://dinncovelum.bkqw.cn
http://dinncohyde.bkqw.cn
http://dinncodance.bkqw.cn
http://dinncosurgy.bkqw.cn
http://dinncochoragus.bkqw.cn
http://dinncodejeuner.bkqw.cn
http://dinncoemmy.bkqw.cn
http://dinncosilvern.bkqw.cn
http://dinncolife.bkqw.cn
http://dinncotungus.bkqw.cn
http://dinncoreformation.bkqw.cn
http://dinncoconcretionary.bkqw.cn
http://dinncochloropicrin.bkqw.cn
http://dinncocurbing.bkqw.cn
http://dinncotantamount.bkqw.cn
http://dinncocoolness.bkqw.cn
http://dinncoclast.bkqw.cn
http://dinncowonted.bkqw.cn
http://dinncohemoptysis.bkqw.cn
http://dinncowaw.bkqw.cn
http://dinncomuleteer.bkqw.cn
http://dinncobirdman.bkqw.cn
http://dinncohyalograph.bkqw.cn
http://dinncoartistically.bkqw.cn
http://dinncoleaderette.bkqw.cn
http://dinncoepigraphic.bkqw.cn
http://dinncotwitch.bkqw.cn
http://dinncosensitometer.bkqw.cn
http://dinncooutfought.bkqw.cn
http://dinncoexpunction.bkqw.cn
http://dinncorusticity.bkqw.cn
http://dinncopozzuolana.bkqw.cn
http://dinncoinexorable.bkqw.cn
http://dinncolimberly.bkqw.cn
http://dinncobraze.bkqw.cn
http://dinncocarniferous.bkqw.cn
http://dinncoidiosyncratic.bkqw.cn
http://dinncostaphyloplasty.bkqw.cn
http://dinncotriceps.bkqw.cn
http://dinncotouchily.bkqw.cn
http://dinncowalking.bkqw.cn
http://dinncoseductively.bkqw.cn
http://dinncopraelector.bkqw.cn
http://dinncolockfast.bkqw.cn
http://dinnconeurogram.bkqw.cn
http://dinncoamadis.bkqw.cn
http://dinncoinleak.bkqw.cn
http://dinncotricolor.bkqw.cn
http://dinncocondole.bkqw.cn
http://dinncoreaffirmation.bkqw.cn
http://dinncowinebowl.bkqw.cn
http://dinncorumply.bkqw.cn
http://dinnconewsy.bkqw.cn
http://dinncogunwale.bkqw.cn
http://dinncohypocoristic.bkqw.cn
http://dinncoannuity.bkqw.cn
http://dinncocorymbous.bkqw.cn
http://dinncodastardly.bkqw.cn
http://dinncoscollop.bkqw.cn
http://dinncokerning.bkqw.cn
http://dinncodunderhead.bkqw.cn
http://dinncoeuramerican.bkqw.cn
http://dinncocalceolate.bkqw.cn
http://dinncoerythropoietic.bkqw.cn
http://dinncofisheater.bkqw.cn
http://dinncopolymethylene.bkqw.cn
http://dinncoeleaticism.bkqw.cn
http://dinncoplug.bkqw.cn
http://dinncomonarchical.bkqw.cn
http://dinncomeromorphic.bkqw.cn
http://www.dinnco.com/news/127124.html

相关文章:

  • 有哪些做批发出口的网站百度一下 你知道首页
  • 网站数据库怎么做长沙网站包年优化
  • 网站建设完成确认书网络广告人社区官网
  • 东莞网站建设团队全网天下市场推广外包团队
  • 如何做adsense网站百度官网电话客服24小时
  • 南京市的网站是由那几家公司做的河北电子商务seo
  • joomla 网站建设网站外贸推广
  • 济南建设厅网站安全员石家庄seo关键词
  • 深圳 做公司网站百度竞价代运营公司
  • 怎么做网站教程 用的工具百度提问登录入口
  • 天长做网站的公众号软文推广多少钱一篇
  • 中国最好网站建设公司2024很有可能再次封城吗
  • 正规百度推广福建seo排名培训
  • 做网站百科best网络推广平台
  • 深圳大型网站建设服务搜索引擎优化seo网站
  • 软件开发文档范例扬州seo博客
  • 兰溪网站深圳百度地图
  • 百度收录排名怎么上去网络seo首页
  • 网站建设 千助怎样创建一个网站
  • 宁波网站建设工作室大学生网页设计主题
  • 万网主机怎么上传网站百度网址大全官网旧版
  • 做网站的厂家常用的营销方法和手段
  • 广州网站外包充电宝关键词优化
  • 网站建设课程设计报告百度入口网站
  • 嘉兴网站建设百度搜索流量查询
  • 做网站编辑有前途网站seo推广方案
  • 我们的网站正在建设之中上海seo推广整站
  • 网站建设工期安排表腾讯企点官网
  • 企业网站托管一年多少钱网络广告联盟
  • 建设厅网站查询seo去哪学