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

邯郸单位网站建设域名注册后怎么使用

邯郸单位网站建设,域名注册后怎么使用,男科医院网站建设公司,合肥公司网站建设价格简介 几乎没有单纯之考察队列的#xff0c;队列一般只作为一个辅助工具 队列常服务于BFS queue接口 1.N叉树的层序遍历 link: 思路#xff1a; 队列 层序遍历即可 code /* // Definition for a Node. class Node { public:int val;vectorNode* children;Node()…简介 几乎没有单纯之考察队列的队列一般只作为一个辅助工具 队列常服务于BFS queue接口 1.N叉树的层序遍历 link: 思路 队列 层序遍历即可 code /* // Definition for a Node. class Node { public:int val;vectorNode* children;Node() {}Node(int _val) {val _val;}Node(int _val, vectorNode* _children) {val _val;children _children;} }; */class Solution { public:vectorvectorint levelOrder(Node* root) {if(!root) return {};vectorvectorint ans;queueNode* que;que.push(root);while(!que.empty()){int sz que.size();vectorint tmp;while(sz--){Node* pop que.front();tmp.push_back(pop-val);que.pop();for(auto e:pop-children){que.push(e);}}ans.push_back(tmp);}return ans;} }; 2.二叉树的锯齿形层序遍历 link:103. 二叉树的锯齿形层序遍历 - 力扣LeetCode 思路 在层序遍历基础上根据deep翻转即可 code /*** 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:vectorvectorint zigzagLevelOrder(TreeNode* root) {// 在层序遍历基础上来个标记为即可if(!root) return {};int deep 0;// deep % 2 0 时需要逆序vectorvectorint ans;queueTreeNode* que;que.push(root);while(!que.empty()){deep;vectorint tmp {};int sz que.size();for(int i 0; i sz; i){TreeNode* pop que.front();que.pop();tmp.push_back(pop-val);if(pop-left)que.push(pop-left);if(pop-right)que.push(pop-right);}if(deep % 2 0)//逆序{reverse(tmp.begin(), tmp.end());}ans.push_back(tmp);}return ans;} }; 3.二叉树的最大宽度 link:662. 二叉树最大宽度 - 力扣LeetCode 思路 数组存储树 双端队列 同余定理 即使最后参与运算的数据很大会int溢出        但是因为是减操作只要结果不会溢出int结果就是正确的 unsigned 在溢出时不会报错 code1 /*** 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 widthOfBinaryTree(TreeNode* root) {// vector 模拟双端队列// 同余定理保证即使int溢出 结果也会正确if(!root) return 0;unsigned ans 1;vectorpairTreeNode*, unsigned dque {{root, 1}};// unsigned 防止溢出报错while(!dque.empty()){ans max(ans, dque.back().second - dque[0].second 1);int sz dque.size();for(int i 0; i sz; i){pairTreeNode*, unsigned out dque[0];dque.erase(dque.begin());if(out.first-left) dque.push_back({out.first-left, out.second * 2});if(out.first-right) dque.push_back({out.first-right, out.second * 2 1});}}return ans;} }; code2 两个vector而不是一个队列在层序遍历时会更方便简洁明了 同时使用结构化绑定 /*** 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 widthOfBinaryTree(TreeNode* root) {if(!root) return 0;unsigned ans 1;vectorpairTreeNode*, unsigned vt {{root, 1}};while(vt.size()){decltype(vt) tmp {};auto [x1, y1] vt[0];auto [x2, y2] vt.back();ans max(ans, y2 - y1 1);for(auto [node, val] : vt){if(node-left) tmp.push_back({node-left, val * 2});if(node-right) tmp.push_back({node-right, val * 2 1});}vt.swap(tmp);}return ans;} }; 4.在每个树行中寻找最大值 link:515. 在每个树行中找最大值 - 力扣LeetCode 思路 层序遍历即可 code 两个vector代替que简洁明了方便易懂 /*** 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:vectorint largestValues(TreeNode* root) {if(!root) return {};vectorint ans;vectorTreeNode* vt {root};while(!vt.empty()){int maxn vt[0]-val;decltype(vt) tmp {};for(auto node : vt){maxn max(maxn, node-val);if(node-left) tmp.push_back(node-left);if(node-right) tmp.push_back(node-right);}vt.swap(tmp);ans.push_back(maxn);}return ans;} };
http://www.dnsts.com.cn/news/2022.html

相关文章:

  • 更换wordpress主题头部seo优化及推广如何运营
  • 罗湖网站建设价格优化关键词排名的工具
  • 什么是门户类型的网站百度推广官方网站登录入口
  • 深圳做网站推广公司张家界网站seo
  • 电商网站图片是谁做媒体平台推广
  • 甘肃住房城乡建设厅网站如何搭建企业网站
  • 可以做问卷的网站有哪些常见的线下推广渠道有哪些
  • 太原网站建设服务热线网络优化的三个方法
  • wordpress 登录不了seo优化信
  • 武汉市住房和城乡建设局网站上海哪家seo好
  • 北京做网站的网络整合营销是什么意思
  • 扁平图标网站网站优化课程培训
  • 做批发网站有哪些免费单页网站在线制作
  • 在线看视频网站怎么做企业网站建设的一般要素
  • wordpress回收站+恢复seo排名是什么意思
  • 培训类网站开发推广自己的网站
  • 郑州网站建设专业公司sem是什么意思
  • 苏州pc网站开发百度一下你就知道官页
  • 不花钱怎么做网站运营seo网站建设公司
  • CSS3网站推广有哪些搜索引擎网站
  • 搭建网站 网页seo引擎优化培训
  • 素材下载网站开发交换链接
  • 乐清app开发公司google关键词seo
  • 网站建设 关于我们西安seo排名
  • 国际网站怎么样做什么是引流推广
  • 石家庄做网站的网址大全实用网址
  • 弹幕网站怎么做网站提交百度收录
  • wordpress软件站主题高端企业网站模板
  • 浙江省网站重点学科建设青岛seo推广公司
  • 单页面 网站 模板足球排名世界排名