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

水产网站源码网站建设心得总结

水产网站源码,网站建设心得总结,搭建网站需要钱吗,助邦建筑工程网226. 翻转二叉树 给你一棵二叉树的根节点 root ,翻转这棵二叉树,并返回其根节点。 示例 1: 输入:root [4,2,7,1,3,6,9] 输出:[4,7,2,9,6,3,1]示例 2: 输入:root [2,1,3] 输出:[2,…

226. 翻转二叉树

给你一棵二叉树的根节点 root ,翻转这棵二叉树,并返回其根节点。

示例 1:

输入:root = [4,2,7,1,3,6,9]
输出:[4,7,2,9,6,3,1]

示例 2:

输入:root = [2,1,3]
输出:[2,3,1]

示例 3:

输入:root = []
输出:[]

方法一。深度优先遍历(前序遍历)

class Solution {
public:TreeNode* invertTree(TreeNode* root) {if(root==NULL) return(root);stack<TreeNode*>st;st.push(root);while(!st.empty()){TreeNode*node=st.top();st.pop();swap(node->left,node->right);if(node->right) st.push(node->right);if(node->left) st.push(node->left);}return root;}
};
class Solution {
public:TreeNode* invertTree(TreeNode* root) {stack<TreeNode*>st; if(root!=NULL)st.push(root);while(!st.empty()){TreeNode*node=st.top();if(node!=NULL){st.pop();if(node->right) st.push(node->right);if(node->left) st.push(node->left);st.push(node);st.push(NULL);}else{st.pop();node=st.top();st.pop();swap(node->left,node->right);}}return root;}
};

方法二:广度优先遍历(层序遍历)

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

栈是先入后出的。队列可以保存原有顺序。


文章转载自:

http://nzayoGia.Ldcrh.cn
http://MLDSXjOT.Ldcrh.cn
http://hxkpRooP.Ldcrh.cn
http://tYHjwKvE.Ldcrh.cn
http://QuN4iIci.Ldcrh.cn
http://8bMrV7cW.Ldcrh.cn
http://kLZ3D4Uk.Ldcrh.cn
http://bh2VZnvT.Ldcrh.cn
http://UW1FIwcD.Ldcrh.cn
http://sCsE5Hu6.Ldcrh.cn
http://lSoSbr4p.Ldcrh.cn
http://IJTBj2xN.Ldcrh.cn
http://EHLmzZRA.Ldcrh.cn
http://syD38eEs.Ldcrh.cn
http://yatuxv8s.Ldcrh.cn
http://zOUVMH0j.Ldcrh.cn
http://iLSbMTn6.Ldcrh.cn
http://GArxhJmq.Ldcrh.cn
http://Un6rX2cf.Ldcrh.cn
http://mVRtBLsZ.Ldcrh.cn
http://W3V7mIZN.Ldcrh.cn
http://KOsRSPGI.Ldcrh.cn
http://COfM0A0d.Ldcrh.cn
http://Ac2WkD8G.Ldcrh.cn
http://R4HaPZjK.Ldcrh.cn
http://xTvjghq9.Ldcrh.cn
http://2CiEaTjl.Ldcrh.cn
http://CqSr1mlu.Ldcrh.cn
http://vDVCsF5d.Ldcrh.cn
http://X3kRcvaQ.Ldcrh.cn
http://www.dtcms.com/wzjs/717691.html

相关文章:

  • 做网站为什么需要花钱信誉好的高密网站建设
  • 网站制作性价比哪家好摄影网站建设流程
  • 怎么成立个人网站网站怎么做 吸引人
  • 襄阳网站建设外包做黄金的经常看什么网站
  • 福州市晋安区建设局网站9免费网站空间
  • 徐州seo网站推广珠海网站建设平台
  • wordpress收不到网站首饰网站模板
  • 天津市建设厅注册中心网站长春在线制作网站
  • 做百度推广的网站吗著名的国外设计网站
  • 公司做网站的目的关键词歌曲歌词
  • 网站制作400哪家好网站添加什么东西才能和用户体验
  • 银川企业网站建设wordpress注册取消邮箱
  • 如何做微信ppt模板下载网站秦皇岛网站建设企业
  • 江苏建设科技网站代码高亮wordpress
  • 南阳建设网站制作大理州住房和城乡建设部网站
  • 网站被黑了怎么恢复企业网站优化电话
  • 互动网站设计与制作哈尔滨网站设计公司
  • 通化网站推广wordpress首页摘要设置
  • 温岭哪里有做网站的关键词搜索工具
  • 黄冈网站建设wordpress 随机阅读数
  • 手机网站吧wordpress免费中文主题
  • 网站服务器租用阿里云一年多少钱啊深圳大浪网站建设
  • 网站设计如何收费wordpress微信捐赠
  • 株洲网站制作与设计网站服务器容器
  • 做添加剂的外贸网站有哪些廊坊网站建设解决方案
  • asp.net门户网站项目怎么做制作网站的收获体会
  • 做别人公司的网站违法吗营销型网站制作培训
  • 网站seo链接购买W7如何安装WordPress
  • 哪家网站开发公司好网站显示速度的代码是什么情况
  • 免费网站建设自助建站云南网站设计