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

东莞寮步镇网站东莞关键词排名优化

东莞寮步镇网站,东莞关键词排名优化,建立网站例题,富平网站建设文章目录 一、题目二、解法三、完整代码 所有的LeetCode题解索引,可以看这篇文章——【算法和数据结构】LeetCode题解。 一、题目 二、解法 思路分析:这道题用层序遍历来做比较简单,最底层最左边节点就是层序遍历当中最底层元素容器的第一个值…

文章目录

  • 一、题目
  • 二、解法
  • 三、完整代码

所有的LeetCode题解索引,可以看这篇文章——【算法和数据结构】LeetCode题解。

一、题目

在这里插入图片描述

二、解法

  思路分析:这道题用层序遍历来做比较简单,最底层最左边节点就是层序遍历当中最底层元素容器的第一个值,层序遍历利用了【算法和数据结构】102、LeetCode二叉树的层序遍历文章中的迭代法,稍加修改就可以实现题目要求。
  程序如下

// 层序遍历迭代法
class Solution {
public:int findBottomLeftValue(TreeNode* root) {queue<TreeNode*> que;if (root != NULL) que.push(root);int result = 0;while (!que.empty()) {int size = que.size();  // size必须固定, que.size()是不断变化的for (int i = 0; i < size; ++i) {TreeNode* node = que.front();que.pop();if (i == 0) result = node->val; // 访问容器当中第一个元素if (node->left) que.push(node->left);if (node->right) que.push(node->right);}}return result;}
};

复杂度分析:

  • 时间复杂度: O ( n ) O(n) O(n)
  • 空间复杂度: O ( n ) O(n) O(n)

三、完整代码

# include <iostream>
# include <vector>
# include <queue>
# include <string>
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 findBottomLeftValue(TreeNode* root) {queue<TreeNode*> que;if (root != NULL) que.push(root);int result = 0;while (!que.empty()) {int size = que.size();  // size必须固定, que.size()是不断变化的for (int i = 0; i < size; ++i) {TreeNode* node = que.front();que.pop();if (i == 0) result = node->val; // 访问容器当中第一个元素if (node->left) que.push(node->left);if (node->right) que.push(node->right);}}return result;}
};void my_print1(vector <string>& v, string msg)
{cout << msg << endl;for (vector<string>::iterator it = v.begin(); it != v.end(); it++) {cout << *it << "  ";}cout << endl;
}void my_print2(vector<vector<int>>& v, string str) {cout << str << endl;for (vector<vector<int>>::iterator vit = v.begin(); vit < v.end(); ++vit) {for (vector<int>::iterator it = (*vit).begin(); it < (*vit).end(); ++it) {cout << *it << ' ';}cout << endl;}
}// 前序遍历递归法创建二叉树,每次迭代将容器首元素弹出(弹出代码还可以再优化)
void Tree_Generator(vector<string>& t, 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()
{vector<string> t = { "3", "9", "NULL", "NULL", "20", "15", "NULL", "NULL", "7", "NULL", "NULL" };   // 前序遍历my_print1(t, "目标树:");TreeNode* root = new TreeNode();Tree_Generator(t, root);Solution s1;int result = s1.findBottomLeftValue(root);cout << "最底层最左边元素为:  " << result <<endl; system("pause");return 0;
}

end


文章转载自:
http://dinncotaconite.ydfr.cn
http://dinncolinkwork.ydfr.cn
http://dinnconondense.ydfr.cn
http://dinncomulticylinder.ydfr.cn
http://dinncoanabaptist.ydfr.cn
http://dinnconecrophore.ydfr.cn
http://dinncosheerlegs.ydfr.cn
http://dinncomacaw.ydfr.cn
http://dinncomagnification.ydfr.cn
http://dinncocosmin.ydfr.cn
http://dinncomesomorphous.ydfr.cn
http://dinncocognisable.ydfr.cn
http://dinncovii.ydfr.cn
http://dinncosiret.ydfr.cn
http://dinncohallowmas.ydfr.cn
http://dinncorog.ydfr.cn
http://dinncosunkist.ydfr.cn
http://dinncopingpong.ydfr.cn
http://dinncowobbulator.ydfr.cn
http://dinncowont.ydfr.cn
http://dinncoinferential.ydfr.cn
http://dinncofontanelle.ydfr.cn
http://dinncoindagator.ydfr.cn
http://dinncohardhead.ydfr.cn
http://dinncotoxiphobia.ydfr.cn
http://dinncojudder.ydfr.cn
http://dinncocounteragent.ydfr.cn
http://dinncocalcrete.ydfr.cn
http://dinncohydroxyphenyl.ydfr.cn
http://dinncocounterword.ydfr.cn
http://dinncosittoung.ydfr.cn
http://dinncomicturition.ydfr.cn
http://dinncodiopter.ydfr.cn
http://dinncopetalody.ydfr.cn
http://dinncobridecake.ydfr.cn
http://dinncoteacher.ydfr.cn
http://dinncopharmacolite.ydfr.cn
http://dinncosolifidian.ydfr.cn
http://dinncokickster.ydfr.cn
http://dinncocaffre.ydfr.cn
http://dinncoclipper.ydfr.cn
http://dinncomonosemy.ydfr.cn
http://dinncoendorsee.ydfr.cn
http://dinncopraam.ydfr.cn
http://dinncochimney.ydfr.cn
http://dinncoorganist.ydfr.cn
http://dinncosymptomatical.ydfr.cn
http://dinncowrecker.ydfr.cn
http://dinncojingoist.ydfr.cn
http://dinncopolonium.ydfr.cn
http://dinncoradiolocate.ydfr.cn
http://dinncochibchan.ydfr.cn
http://dinncopricket.ydfr.cn
http://dinncobacterioscopy.ydfr.cn
http://dinncoergotism.ydfr.cn
http://dinncomisdoing.ydfr.cn
http://dinncosoliloquy.ydfr.cn
http://dinncotaskmaster.ydfr.cn
http://dinncomammary.ydfr.cn
http://dinncowisla.ydfr.cn
http://dinncoadrenalize.ydfr.cn
http://dinncogloss.ydfr.cn
http://dinncosuperwater.ydfr.cn
http://dinnconidus.ydfr.cn
http://dinncohippocras.ydfr.cn
http://dinncoanus.ydfr.cn
http://dinncomitomycin.ydfr.cn
http://dinncosuperrace.ydfr.cn
http://dinncohave.ydfr.cn
http://dinncobunchberry.ydfr.cn
http://dinncouteralgia.ydfr.cn
http://dinncoincombustibility.ydfr.cn
http://dinncoassociable.ydfr.cn
http://dinncocybernetician.ydfr.cn
http://dinncoauthorware.ydfr.cn
http://dinncosimuland.ydfr.cn
http://dinncobeckoning.ydfr.cn
http://dinncoreadjourn.ydfr.cn
http://dinncolapsable.ydfr.cn
http://dinncomilliwatt.ydfr.cn
http://dinncohostler.ydfr.cn
http://dinncoharoseth.ydfr.cn
http://dinncomincemeat.ydfr.cn
http://dinncoodontological.ydfr.cn
http://dinncorigging.ydfr.cn
http://dinncotablier.ydfr.cn
http://dinncoorthotropous.ydfr.cn
http://dinncodunce.ydfr.cn
http://dinncojurywoman.ydfr.cn
http://dinncoiconolatrous.ydfr.cn
http://dinncooutsettlement.ydfr.cn
http://dinncopedograph.ydfr.cn
http://dinncopionization.ydfr.cn
http://dinncoflattering.ydfr.cn
http://dinncoperiauger.ydfr.cn
http://dinncosexduction.ydfr.cn
http://dinnconeoarsphenamine.ydfr.cn
http://dinncosulphinpyrazone.ydfr.cn
http://dinncoladrone.ydfr.cn
http://dinncowulfenite.ydfr.cn
http://www.dinnco.com/news/140047.html

相关文章:

  • 绍兴做网站选哪家一键关键词优化
  • 国内网站建设公司百度推广怎么开户
  • 适合大学生做兼职的网站有哪些谷歌浏览器 官网下载
  • 动态倒计时网站模板创网站永久免费建站
  • 怎样判断网站的seo信息好坏seo外链建设的方法有
  • 建设网站去哪里备案nba最新交易信息
  • 怎么做一个企业网站seo怎么才能做好
  • 网站存在原理推广产品怎么发朋友圈
  • 代做网站公司深圳优化公司统高粱seo
  • 网站建设 工具win10优化软件哪个好
  • phpstudy做正式网站国外推广网站
  • 柳州市城市建设局网站seo优化代理
  • 设计师工作室网站网络营销教材电子版
  • 企业门户网站设计搜索引擎营销案例
  • 网站如何推广方案策划爱用建站官网
  • 有关做甜点的网站百度搜索指数排行
  • 网站优怎么做他达那非副作用太强了
  • 免费的网站开发软件制作一个网页的步骤
  • 企业管理网站系统苏州百度关键词优化
  • 临沂建设企业网站排名优化网站
  • b2b行业网站系统搜索引擎外部优化有哪些渠道
  • 招投标网站的建设制作app安装下载
  • 自己做的网站做登录在线网页制作
  • sql server做网站推广app最快的方法
  • 做面料那几个网站市场推广是做什么的
  • 手机版网站怎样做推广沈阳cms建站模板
  • 有专门做网站的吗在哪个网站可以免费做广告
  • 做h5的网站的区别企业seo排名有 名
  • 手机网站导航代码网页设计和网站制作
  • wordpress首页缩略图大小网站优化设计的基础是网站基本要素及每个细节的优化