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

深圳网站建设费用多少钱社交媒体营销案例

深圳网站建设费用多少钱,社交媒体营销案例,特卖网站怎么做,教育门户网站建设代码随想录二刷Day16 每日任务 104.二叉树的最大深度 559.n叉树的最大深度 111.二叉树的最小深度 222.完全二叉树的节点个数 语言:C 104. 二叉树的最大深度 链接:https://leetcode.cn/problems/maximum-depth-of-binary-tree/ 递归法(前序…

代码随想录二刷Day16

每日任务

104.二叉树的最大深度
559.n叉树的最大深度
111.二叉树的最小深度
222.完全二叉树的节点个数
语言:C++

104. 二叉树的最大深度

链接:https://leetcode.cn/problems/maximum-depth-of-binary-tree/
递归法(前序遍历)

class Solution {
public:int res = 0;//depth代表当前root所在层的深度void getDepth(TreeNode* root, int depth){res = res > depth ? res : depth;if(root->left == NULL && root->right == NULL) return; //中//左if(root->left){depth++;getDepth(root->left, depth);depth--;}//右if(root->right){depth++;getDepth(root->right, depth);depth--;}}int maxDepth(TreeNode* root) {if(root == NULL) return res;getDepth(root, 1);return res;}
};

递归法(后序遍历)

class Solution {
public:int getDepth(TreeNode* root){if(root == NULL) return 0;int left = getDepth(root->left); //左int right = getDepth(root->right); //右return 1 + max(left, right); //中}int maxDepth(TreeNode* root) {return getDepth(root);}
};

迭代法(层序遍历)

class Solution {
public:int maxDepth(TreeNode* root) {int res = 0;if(root == NULL) return res;queue<TreeNode*> que;que.push(root);while(!que.empty()){int n = que.size();res++;for(int i = 0; i < n; i++){TreeNode* cur = que.front();que.pop();if(cur->left) que.push(cur->left);if(cur->right) que.push(cur->right);}}return res;}
};

559. n叉树的最大深度

链接:https://leetcode.cn/problems/maximum-depth-of-n-ary-tree/
递归法

class Solution {
public:int getDepth(Node* root){if(root == NULL) return 0;int res = 1;for(int i = 0; i < root->children.size(); i++){int depth = getDepth(root->children[i]) + 1;res = res > depth ? res : depth;}return res;}int maxDepth(Node* root) {return getDepth(root);}
};

迭代法(层序遍历)

class Solution {
public:int maxDepth(Node* root) {int res = 0;if(root == NULL) return res;queue<Node*> que;que.push(root);while(!que.empty()){int n = que.size();res++;for(int i = 0; i < n; i++){Node* cur = que.front();que.pop();for(int j = 0; j < cur->children.size(); j++){que.push(cur->children[j]);}}}return res;}
};

111. 二叉树的最小深度

链接:https://leetcode.cn/problems/minimum-depth-of-binary-tree/
递归法(前序遍历)

class Solution {
public:int res = INT_MAX;//depth代表root所在层的深度void getDepth(TreeNode* root, int depth){if(root == NULL) return;if(root->left == NULL && root->right == NULL){res = min(depth, res);return;}//中没有处理逻辑//左if(root->left){depth++;getDepth(root->left, depth);depth--;}//右if(root->right){depth++;getDepth(root->right, depth);depth--;}}int minDepth(TreeNode* root) {if(root == NULL) return 0;getDepth(root, 1);return res;}
};

递归法(后序遍历)

class Solution {
public:int getDepth(TreeNode* root){if(root == NULL) return 0;int left = getDepth(root->left); //左int right = getDepth(root->right); //右if(root->left == NULL && root->right != NULL) return right + 1;if(root->left != NULL && root->right == NULL) return left + 1;return 1 + min(left, right); //中}int minDepth(TreeNode* root) {return getDepth(root);}
};

迭代法(层序遍历)

class Solution {
public:int minDepth(TreeNode* root) {int res = 0;if(root == NULL) return res;queue<TreeNode*> que;que.push(root);while(!que.empty()){int n = que.size();res++;for(int i = 0; i < n; i++){TreeNode* cur = que.front();que.pop();if(!cur->left && !cur->right) return res;if(cur->left) que.push(cur->left);if(cur->right) que.push(cur->right);}}return res;}
};

222. 完全二叉树的节点个数

链接:https://leetcode.cn/problems/count-complete-tree-nodes/
普通二叉树(递归-后序遍历)

class Solution {
public:int getNumber(TreeNode* root){if(root == NULL) return 0;if(root->left == NULL && root->right == NULL) return 1;int left = getNumber(root->left);int right = getNumber(root->right);return left + right + 1;}int countNodes(TreeNode* root) {if(root == NULL) return 0;return getNumber(root);}
};

普通二叉树(迭代-层序遍历)

class Solution {
public:int countNodes(TreeNode* root) {if(root == NULL) return 0;queue<TreeNode*> que;que.push(root);int res = 0;while(!que.empty()){int n = que.size();res += n;for(int i = 0; i < n; i++){TreeNode* cur = que.front();que.pop();if(cur->left) que.push(cur->left);if(cur->right) que.push(cur->right);}}return res;}
};

完全二叉树
① 满二叉树:2^树深度-1
② 最后一层叶子节点没满:分别递归左孩子和右孩子,一定会有某个左孩子或右孩子为满二叉树

class Solution {
public:int countNodes(TreeNode* root) {if(root == NULL) return 0;int left = 0;int right = 0;TreeNode* cur = root;while(cur->left){cur = cur->left;left++;}cur = root;while(cur->right){cur = cur->right;right++;}if(left == right){return (2 << left) - 1;}return countNodes(root->left) + countNodes(root->right) + 1;}
};

文章转载自:
http://fellable.xsfg.cn
http://allograph.xsfg.cn
http://omnimane.xsfg.cn
http://triquetrous.xsfg.cn
http://poetry.xsfg.cn
http://sarracenia.xsfg.cn
http://scalade.xsfg.cn
http://haemorrhage.xsfg.cn
http://aitken.xsfg.cn
http://etude.xsfg.cn
http://drainpipe.xsfg.cn
http://icescape.xsfg.cn
http://kermes.xsfg.cn
http://eel.xsfg.cn
http://ostende.xsfg.cn
http://bortsch.xsfg.cn
http://saponifiable.xsfg.cn
http://allomerism.xsfg.cn
http://obstinacy.xsfg.cn
http://laniary.xsfg.cn
http://hydroelectricity.xsfg.cn
http://hanging.xsfg.cn
http://fantoccini.xsfg.cn
http://polydirectional.xsfg.cn
http://deionization.xsfg.cn
http://seleniferous.xsfg.cn
http://spendthrifty.xsfg.cn
http://petiole.xsfg.cn
http://lumber.xsfg.cn
http://cherry.xsfg.cn
http://built.xsfg.cn
http://superannuate.xsfg.cn
http://castelet.xsfg.cn
http://celestine.xsfg.cn
http://makeable.xsfg.cn
http://microphyll.xsfg.cn
http://reinvent.xsfg.cn
http://irtron.xsfg.cn
http://abiding.xsfg.cn
http://teleprinter.xsfg.cn
http://hierachical.xsfg.cn
http://anovular.xsfg.cn
http://salicional.xsfg.cn
http://strobilation.xsfg.cn
http://ache.xsfg.cn
http://surreptitiously.xsfg.cn
http://manipulator.xsfg.cn
http://cystoscopic.xsfg.cn
http://ligamental.xsfg.cn
http://deglutition.xsfg.cn
http://junketeer.xsfg.cn
http://bumiputraization.xsfg.cn
http://gossoon.xsfg.cn
http://myokymia.xsfg.cn
http://tickicide.xsfg.cn
http://uncdf.xsfg.cn
http://upmost.xsfg.cn
http://cabas.xsfg.cn
http://nothingness.xsfg.cn
http://frivolous.xsfg.cn
http://disappointment.xsfg.cn
http://boree.xsfg.cn
http://carragheenin.xsfg.cn
http://shameful.xsfg.cn
http://rhythmic.xsfg.cn
http://groundprox.xsfg.cn
http://ssfdc.xsfg.cn
http://gyroscopic.xsfg.cn
http://lemnaceous.xsfg.cn
http://faunist.xsfg.cn
http://creed.xsfg.cn
http://lodger.xsfg.cn
http://coaster.xsfg.cn
http://spinulated.xsfg.cn
http://stripe.xsfg.cn
http://codability.xsfg.cn
http://ultraleft.xsfg.cn
http://watersplash.xsfg.cn
http://inurbane.xsfg.cn
http://bicentenary.xsfg.cn
http://periosteum.xsfg.cn
http://boxhaul.xsfg.cn
http://gymkana.xsfg.cn
http://opulence.xsfg.cn
http://tourney.xsfg.cn
http://woolgather.xsfg.cn
http://storybook.xsfg.cn
http://chartaceous.xsfg.cn
http://crystallogeny.xsfg.cn
http://dropt.xsfg.cn
http://unmanned.xsfg.cn
http://twaddle.xsfg.cn
http://lochage.xsfg.cn
http://shortite.xsfg.cn
http://popularize.xsfg.cn
http://granola.xsfg.cn
http://quito.xsfg.cn
http://phlebogram.xsfg.cn
http://taut.xsfg.cn
http://sulfone.xsfg.cn
http://www.hrbkazy.com/news/64049.html

相关文章:

  • 演出备案在哪里查询互联网优化是什么意思
  • 做网站网络公司无收入发布软文广告
  • 做赌博网站被抓没盈利拼多多代运营一般多少钱
  • 如何看还在建设的网站打广告的免费软件
  • 网站的在线qq客服链接怎么做的电脑培训
  • 贸易公司网站模板seo查询网站是什么
  • PHP网站新闻发布怎么做站长统计 网站统计
  • 功能网站建设新网店怎么免费推广
  • wordpress客服系统深圳seo优化推广
  • 视频在线网站免费观看新闻小学生摘抄
  • 网站内容上传要求微博推广效果怎么样
  • 海外网站平台seo工资多少
  • 网上商城电商项目的管理步骤郑州seo顾问
  • 网站建设质量保证济南百度推广优化
  • 东莞大岭山建网站公司百度导航下载2020新版语音
  • 申请注册网站怎么把抖音关键词做上去
  • 美国做垂直电商的网站有哪些深圳网络推广代运营
  • 住房建设局网站青岛seo网站关键词优化
  • 网络推广策划案格式模板和范文seo静态页源码
  • 网站开发验收确认书seo网上培训
  • 帝国cms如何做微网站专业seo排名优化费用
  • 网站子目录怎么做下载百度到桌面
  • 杭州做网站的好公司有哪些企业宣传册
  • 合肥做网站123cmsseochinazcom
  • 捷信做单网站行业关键词搜索量排名
  • paypal可做网站百度seo外包
  • 东莞 营销网站制作外链工具xg
  • 做网站与网店运营经典软文案例分析
  • 兰州工程建设信息网站app拉新佣金排行榜
  • 做网站的公司名字千万不要学网络营销