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

wordpress动漫整站买个网站域名多少钱一年

wordpress动漫整站,买个网站域名多少钱一年,海外培训视频网站建设,系统开发人员有哪几类文章目录 一、题目二、层序遍历法三、递归法四、完整代码 所有的LeetCode题解索引#xff0c;可以看这篇文章——【算法和数据结构】LeetCode题解。 一、题目 二、层序遍历法 思路分析#xff1a;两道题都可以用层序遍历#xff08;迭代法#xff09;来做#xff0c;遍历完… 文章目录 一、题目二、层序遍历法三、递归法四、完整代码 所有的LeetCode题解索引可以看这篇文章——【算法和数据结构】LeetCode题解。 一、题目 二、层序遍历法 思路分析两道题都可以用层序遍历迭代法来做遍历完一层深度变量depth就。找最小深度实际上等价于找离根节点最近的叶子节点我们在遍历每一个节点时判断它的左右节点是否为空若为空则为叶子节点输出此时的depth。   找最大深度程序如下 class Solution { public:// 找最大深度int maxDepth(TreeNode* root) {queueTreeNode* que;if (root ! NULL) que.push(root);int Depth 0, size 0; // 根节点深度定义为1while (!que.empty()) {Depth;size que.size(); // size必须固定, que.size()是不断变化的for (int i 0; i size; i) {TreeNode* node que.front();que.pop();if (node-left) que.push(node-left);if (node-right) que.push(node-right);} }return Depth;} };找最小深度程序如下 class Solution2 { public:// 找最小深度int minDepth(TreeNode* root) {if (!root) return 0;queueTreeNode* que;que.push(root);int Depth 0, size 0; // 根节点深度定义为1while (!que.empty()) {Depth;size que.size(); // size必须固定, que.size()是不断变化的for (int i 0; i size; i) {TreeNode* node que.front();que.pop();if (node-left NULL node-right NULL) return Depth;if (node-left) que.push(node-left);if (node-right) que.push(node-right);}}return Depth;} };三、递归法 当然这道题也可以用递归法实现。一般的递归法我们需要注意三个点 1、输入参数和返回值2、确定终止条件3、确定单层递归逻辑   找最大深度程序如下程序当中终止条件为节点为NULL返回0表示深度为0。依次寻找左右节点的深度然后当前节点的最大深度为左右节点最大值11是因为算上当前中间节点。 class Solution3 { public:// 找最大深度int getDepth(TreeNode* root) {if (!root) return 0;int leftdepth getDepth(root-left);int rightdepth getDepth(root-right);int depth 1 max(leftdepth, rightdepth);return depth;}int maxDepth(TreeNode* root) {return getDepth(root);} };精简版本如下 class Solution3 { public:// 递归法找最大深度简化版int maxDepth(TreeNode* root) {if (!root) return 0;return 1 max(maxDepth(root-left), maxDepth(root-right));} };四、完整代码 # include iostream # include vector # include queue # include string # include algorithm using namespace std;// 树节点定义 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 maxDepth(TreeNode* root) {queueTreeNode* que;if (root ! NULL) que.push(root);int Depth 0, size 0; // 根节点深度定义为1while (!que.empty()) {Depth;size que.size(); // size必须固定, que.size()是不断变化的for (int i 0; i size; i) {TreeNode* node que.front();que.pop();if (node-left) que.push(node-left);if (node-right) que.push(node-right);} }return Depth;} };class Solution2 { public:// 找最小深度int minDepth(TreeNode* root) {if (!root) return 0;queueTreeNode* que;que.push(root);int Depth 0, size 0; // 根节点深度定义为1while (!que.empty()) {Depth;size que.size(); // size必须固定, que.size()是不断变化的for (int i 0; i size; i) {TreeNode* node que.front();que.pop();if (node-left NULL node-right NULL) return Depth;if (node-left) que.push(node-left);if (node-right) que.push(node-right);}}return Depth;} };//class Solution3 { //public: // // 递归法找最大深度 // int getDepth(TreeNode* root) { // if (!root) return 0; // int leftdepth getDepth(root-left); // int rightdepth getDepth(root-right); // int depth 1 max(leftdepth, rightdepth); // return depth; // } // int maxDepth(TreeNode* root) { // return getDepth(root); // } //};class Solution3 { public:// 递归法找最大深度简化版int maxDepth(TreeNode* root) {if (!root) return 0;return 1 max(maxDepth(root-left), maxDepth(root-right));} };void my_print(vector string v, string msg) {cout msg endl;for (vectorstring::iterator it v.begin(); it ! v.end(); it) {cout *it ;}cout endl; }// 前序遍历迭代法创建二叉树每次迭代将容器首元素弹出弹出代码还可以再优化 void Tree_Generator(vectorstringt, TreeNode* node) {if (t[0] NULL || !t.size()) return; // 退出条件else {node new TreeNode(stoi(t[0].c_str())); // 中t.assign(t.begin() 1, t.end());Tree_Generator(t, node-left); // 左t.assign(t.begin() 1, t.end());Tree_Generator(t, node-right); // 右} }int main() {vectorstring t { 3, 9, NULL, NULL, 20, 15, NULL, NULL, 7, NULL, NULL}; // 前序遍历my_print(t, 目标树);TreeNode* root new TreeNode();Tree_Generator(t, root);Solution3 s1;int result s1.maxDepth(root);cout 最大深度为 result endl;system(pause);return 0; }end
http://wiki.neutronadmin.com/news/303544/

相关文章:

  • 大连网站制作网站桂林本地网站
  • 2010年4月江苏省03340网站建设与管理答案上海公司注册核名查询
  • 株洲做网站优化青海中小企业网站建设
  • 推广方式方法网站优化 合同
  • 蛋糕网站案例网络营销推广的平台
  • 可以网上做单的网站有哪些电脑更新wordpress
  • 深圳招聘网站排名东莞市专注网站建设服务机构
  • 网站建设考评表环保空调东莞网站建设
  • 网站怎么做站长统计在旅行社做网站运营
  • 祥云平台网站建设网站搭建教学
  • 方案网站有哪些html5网站源代码
  • 建立网站需要准备的材料广州华优_网站建设公司
  • 石家庄行业网站给军方做网站套模板行不行
  • ci策划 网站开发冬夜主题wordpress
  • 网站所有页面只显示域名平湖市住房和城乡规划建设局网站
  • wap企业网站linux网站开发工具
  • wordpress diy插件广州seo网站多少钱
  • 网站建设咨询有客诚信网站建设咨询泰安市住房和城乡建设部网站
  • 丽水开发区建设局网站廉租房苏州十大广告公司
  • seo站内优化公司知乎类 wordpress
  • 商城购物网站建设方案高端网站建设好的公司
  • 网站等比例缩放帮忙建设公司网站
  • 无锡市网站建设关于申请网站建设的请示
  • 网站服务器免费申请wordpress社交图标
  • 安全质量报监建设局网站全屋定制给设计吗
  • flask做的购物网站青海政企网站建设
  • 女人吃男人做床视频网站wix网站做图片能折叠吗
  • 没有网站可以做京东联盟吗电子商务网站建设与设计论文
  • 做pc网站如何实时预览外贸建网站
  • 酷站海洛网站开发软件 论文 摘要