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

做自己头像的网站软件推广赚钱

做自己头像的网站,软件推广赚钱,沈阳建站平台,外贸如何推广励志冰檗:形容在清苦的生活环境中激励自己的意志。💓💓💓 目录 说在前面 题目一:单值二叉树 题目二:相同的树 题目三:对称二叉树 题目四:二叉树的前序遍历 题目五:另…

励志冰檗:形容在清苦的生活环境中激励自己的意志。💓💓💓

目录

 说在前面

题目一:单值二叉树

题目二:相同的树

题目三:对称二叉树

题目四:二叉树的前序遍历

题目五:另一棵树的子树

题目六:二叉树的构建及遍历

SUMUP结尾


 说在前面

 dear朋友们大家好!💖💖💖我们又见面了,又到了我们数据结构的刷题时间了。我们上次刚学完了二叉树的知识,现在就让我们来练练手~

 👇👇👇

友友们!🎉🎉🎉点击这里进入力扣leetcode学习🎉🎉🎉


​以下是leetcode题库界面:

​​

 👇👇👇

🎉🎉🎉点击这里进入牛客网NowCoder刷题学习🎉🎉🎉
​以下是NowCoder题库界面:

 

题目一:单值二叉树

题目链接:965. 单值二叉树 - 力扣(LeetCode)

题目描述:

题目分析:

思路:对于二叉树的OJ练习我们一定要多利用递归的思想,即将大问题拆成子问题。首先我们考虑,如果树为空,显然也是单值二叉树,返回true;如果节点中的值与它左右子树根节点的值不同,那肯定返回false;如果和它左右子树根节点的值都相同,就递归到左右子树,按照同样的逻辑即可。

代码如下:

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     struct TreeNode *left;*     struct TreeNode *right;* };*/
bool isUnivalTree(struct TreeNode* root) {if(root == NULL)return true;if(root->left && root->val != root->left->val || root->right && root->val != root->right->val)return false;return isUnivalTree(root->left) && isUnivalTree(root->right);
}

 

题目二:相同的树

题目链接:100. 相同的树 - 力扣(LeetCode)

题目描述:

题目分析:

思路:首先,我们需要判断这两棵树是否为空,如果都为空,那么也是相同的树,如果其中有一个为空,另一个不为空,那就不是相同的树;如果第一棵树和第二棵树的值不相等,那肯定不是相同的树;如果它们的值相等,就需要递归到左右子树,如果左右子树都满足,自然最终会回到第一种情况,再将true回归。

 代码如下:

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     struct TreeNode *left;*     struct TreeNode *right;* };*/
bool isSameTree(struct TreeNode* p, struct TreeNode* q) {if(!p && !q)return true;if(!p || !q)return false;return p->val != q->val ? false : isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}

 

题目三:对称二叉树

题目链接:101. 对称二叉树 - 力扣(LeetCode)

题目描述:

题目分析:

思路:这道题的思路和题目二有些许类似,题目二是判断两棵树的左右子树是否相同,而这道题是判断你的左子树和我的右子树是否相同即可,也就是我们把二叉树分为root->left和root->right,利用和题目二相同的逻辑就可以了。

代码如下:

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     struct TreeNode *left;*     struct TreeNode *right;* };*/bool _isSymmetric(struct TreeNode* p, struct TreeNode* q) {if(!p && !q)return true;if(!p || !q)return false;return p->val != q->val ? false : _isSymmetric(p->left, q->right) && _isSymmetric(p->right, q->left); 
}bool isSymmetric(struct TreeNode* root) {return _isSymmetric(root->left, root->right);
}

 

题目四:二叉树的前序遍历

题目链接:144. 二叉树的前序遍历 - 力扣(LeetCode)

题目描述:

题目分析:

思路:我们再上一章二叉树的部分学习过二叉树的前序遍历,但我们之前的前序遍历在遍历过程中的操作是打印节点的值,我们现在的操作是把它存在一个数组arr中。那数组的大小*returnSize是多少呢?显然就是树的节点,所以我们也需要TreeSize函数来计算树的节点。

代码如下:

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     struct TreeNode *left;*     struct TreeNode *right;* };*/
/*** Note: The returned array must be malloced, assume caller calls free().*/typedef struct TreeNode TreeNode;//树的节点个数
int TreeSize(TreeNode* root)
{if(root == NULL)return 0;return TreeSize(root->left) + TreeSize(root->right) + 1;
}//前序遍历
void PrevOrder(TreeNode* root, int* arr, int* pi)
{if(root == NULL)return;arr[(*pi)++] = root->val;PrevOrder(root->left, arr, pi);PrevOrder(root->right, arr, pi);
}int* preorderTraversal(struct TreeNode* root, int* returnSize) {*returnSize = TreeSize(root);int* arr = (int*)malloc((*returnSize) * sizeof(int));int i = 0;PrevOrder(root, arr, &i);return arr;
}

注意:i作为数组arr的下标,会随着递归的深度而进行改变,所以需要传址调用。

 

题目五:另一棵树的子树

题目链接:572. 另一棵树的子树 - 力扣(LeetCode)

题目描述:

题目分析:

思路:这道题我们首先判断root本身是否为空,如果本身为空,显然subRoot不可能是root的子树。如果root不为空,我们判断root和subRoot是否是相同的树(相同的树也算true),如果是就返回true,如果不是,就递归到它的左右子树即可。所以我们还需要用到题目二中的相关代码。

代码如下:

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     struct TreeNode *left;*     struct TreeNode *right;* };*/
//判断两棵树是否相同
bool isSameTree(struct TreeNode* p, struct TreeNode* q) {if(!p && !q)   return true;if(!p || !q)    return false;return p->val != q->val ? false : isSameTree(p->left, q->left) && isSameTree(p->right, q->right);    
}bool isSubtree(struct TreeNode* root, struct TreeNode* subRoot){if(root == NULL)return false;return isSameTree(root, subRoot) ? true :isSubtree(root->left, subRoot) || isSubtree(root->right, subRoot);
}

 

题目六:二叉树的构建及遍历

题目链接:二叉树遍历_牛客题霸_牛客网 (nowcoder.com)

题目描述:

题目分析:

思路:这道题依旧用到了我们上一章中前序和中序遍历的思想,首先构建二叉树我们需要将前序遍历存放在数组arr中,用i作为下标。和题目五类似,i也需要传地址调用。

代码如下:

#include <stdio.h>
#include <stdlib.h>#define MAXSIZE 100typedef char BTDataType;typedef struct BinaryTreeNode
{BTDataType data;struct BinaryTreeNode* left;struct BinaryTreeNode* right;
}BTNode;//二叉树的构建
BTNode* CreateTree(char* arr, int* pi)
{BTNode* root = (BTNode*)malloc(sizeof(BTNode));if(arr[*pi] == '#'){(*pi)++;return NULL;}root->data = arr[(*pi)++];root->left = CreateTree(arr, pi);root->right = CreateTree(arr, pi);return root;
}//中序遍历
void InOrder(BTNode* root)
{if(root == NULL)return;InOrder(root->left);printf("%c ", root->data);InOrder(root->right);
}int main()
{char arr[MAXSIZE];scanf("%s",arr);int i = 0;BTNode* root = CreateTree(arr, &i);InOrder(root);return 0;
}

 

SUMUP结尾

数据结构就像数学题,需要刷题才能对它有感觉。之后还会更新数据结构相关的练习题、面试题,希望大家一起学习,共同进步~

如果大家觉得有帮助,麻烦大家点点赞,如果有错误的地方也欢迎大家指出~


文章转载自:
http://dinncorebunk.bkqw.cn
http://dinncovaticanist.bkqw.cn
http://dinncoconnotate.bkqw.cn
http://dinncorepurchase.bkqw.cn
http://dinncosteeplechase.bkqw.cn
http://dinncoveery.bkqw.cn
http://dinncobrassiness.bkqw.cn
http://dinncomatriculation.bkqw.cn
http://dinncoworryingly.bkqw.cn
http://dinncolymphous.bkqw.cn
http://dinncomazopathy.bkqw.cn
http://dinncopolymethyl.bkqw.cn
http://dinncoscilla.bkqw.cn
http://dinncopneumocele.bkqw.cn
http://dinncorotator.bkqw.cn
http://dinncosubstantial.bkqw.cn
http://dinncosatyromania.bkqw.cn
http://dinncochromograph.bkqw.cn
http://dinncodunbarton.bkqw.cn
http://dinncofootboy.bkqw.cn
http://dinncolandform.bkqw.cn
http://dinncotrilocular.bkqw.cn
http://dinncocubhunting.bkqw.cn
http://dinncoinwall.bkqw.cn
http://dinncoomenta.bkqw.cn
http://dinncocutlass.bkqw.cn
http://dinncoreshuffle.bkqw.cn
http://dinncoperivisceral.bkqw.cn
http://dinncoslightness.bkqw.cn
http://dinncotilsit.bkqw.cn
http://dinncoredrill.bkqw.cn
http://dinncoingvaeonic.bkqw.cn
http://dinncoechinodermata.bkqw.cn
http://dinncoklondike.bkqw.cn
http://dinncomultibucket.bkqw.cn
http://dinncofatherlike.bkqw.cn
http://dinncotephrite.bkqw.cn
http://dinncolotic.bkqw.cn
http://dinncocavecanem.bkqw.cn
http://dinncoantrorse.bkqw.cn
http://dinncoboon.bkqw.cn
http://dinncoaxminster.bkqw.cn
http://dinncomufti.bkqw.cn
http://dinncoglaum.bkqw.cn
http://dinncodiastereoisomer.bkqw.cn
http://dinncosara.bkqw.cn
http://dinncotpn.bkqw.cn
http://dinncomouthpart.bkqw.cn
http://dinncoclosing.bkqw.cn
http://dinncosilverback.bkqw.cn
http://dinncosubumbrella.bkqw.cn
http://dinncodouma.bkqw.cn
http://dinncophotoelement.bkqw.cn
http://dinncoeuphemistic.bkqw.cn
http://dinncoanchor.bkqw.cn
http://dinncomannitol.bkqw.cn
http://dinncopermute.bkqw.cn
http://dinncoliberatress.bkqw.cn
http://dinncowoolenette.bkqw.cn
http://dinncojollo.bkqw.cn
http://dinncojiggly.bkqw.cn
http://dinncowatercart.bkqw.cn
http://dinncocomedown.bkqw.cn
http://dinncoenatic.bkqw.cn
http://dinncoparaumbilical.bkqw.cn
http://dinncorocketsonde.bkqw.cn
http://dinncosemiopaque.bkqw.cn
http://dinnconaggish.bkqw.cn
http://dinncomuhtar.bkqw.cn
http://dinncobubonic.bkqw.cn
http://dinncogiddify.bkqw.cn
http://dinncoconflux.bkqw.cn
http://dinncounsophistication.bkqw.cn
http://dinncotrichiniasis.bkqw.cn
http://dinncocutis.bkqw.cn
http://dinncoinsufferably.bkqw.cn
http://dinncoguttulate.bkqw.cn
http://dinncothrone.bkqw.cn
http://dinncoeffectuation.bkqw.cn
http://dinncoknuckler.bkqw.cn
http://dinncoreliever.bkqw.cn
http://dinncotetrawickmanite.bkqw.cn
http://dinncowaldensian.bkqw.cn
http://dinncohydropical.bkqw.cn
http://dinncotalgo.bkqw.cn
http://dinncofarmland.bkqw.cn
http://dinncomicell.bkqw.cn
http://dinncodextral.bkqw.cn
http://dinncobegin.bkqw.cn
http://dinncochert.bkqw.cn
http://dinncostenographer.bkqw.cn
http://dinncoupbind.bkqw.cn
http://dinncooutrider.bkqw.cn
http://dinncotisiphone.bkqw.cn
http://dinncoscythe.bkqw.cn
http://dinncomycetozoan.bkqw.cn
http://dinncotrothplight.bkqw.cn
http://dinncoskibob.bkqw.cn
http://dinncovanuatuan.bkqw.cn
http://dinncomasterman.bkqw.cn
http://www.dinnco.com/news/126846.html

相关文章:

  • 专门做处理货的网站百度图片收录提交入口
  • 河南省建设厅网站 吴浩网站seo排名优化工具在线
  • 做网站备案需要什么特殊材料博客营销
  • 上市公司中 哪家网站做的好windows优化大师电脑版
  • 网站做产品的审核工作内容企业网址
  • 做网站的职业网址查询服务器地址
  • 怎么才能建设免费网站如何在网上推广自己
  • 做网站开发的公司销售热门搜索
  • 怎么自己设置网站模板百度网盘人工客服电话
  • 帝国cms如何做网站地图推广竞价的公司有哪些
  • 做网站 设计师很软文文案
  • 网站建设协议谷歌浏览器直接打开
  • 如何做360购物网站推广价格一般多少
  • 云阳有没有做网站的西安seo排名收费
  • 为什么要用CGI做网站私人网站服务器
  • 网站上的流动图片怎么做的学校网站建设
  • 做ppt赚钱的网站百度经验app下载
  • 印度网站开发成本福州seo优化排名推广
  • wordpress主题创建数据表上海排名优化seo
  • 推广员网站怎么做seo快速排名首页
  • 英文网站注册河北网站建设公司排名
  • 有做lol直播网站有哪些人2023近期舆情热点事件
  • 大兴模板网站建设百度账号购买1元40个
  • 企业网络方案设计关键词优化一般收费价格
  • 做调查赚钱靠谱的网站有没有专门做策划的公司
  • 网站高质量外链推广形式
  • 汕头网站制作电话网络运营师
  • 怎么做夜场网站郑州seo网站关键词优化
  • 视频网站中滑动列表怎么做seo日常工作内容
  • wordpress调用文章内容图片seo营销推广全程实例