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

微信朋友圈投放广告刷网站seo排名软件

微信朋友圈投放广告,刷网站seo排名软件,苏州建网站必去苏州聚尚网络,怎么注册做鸭网站摘要 博文主要介绍二叉树的前/中/后/层遍历(递归与栈)方法 一、前/中/后/层遍历问题 144. 二叉树的前序遍历 145. 二叉树的后序遍历 94. 二叉树的中序遍历 102. 二叉树的层序遍历 103. 二叉树的锯齿形层序遍历 二、二叉树遍历递归解析 // 前序遍历递归LC144_二叉树的前…

摘要

博文主要介绍二叉树的前/中/后/层遍历(递归与栈)方法

一、前/中/后/层遍历问题

144. 二叉树的前序遍历

145. 二叉树的后序遍历

94. 二叉树的中序遍历

102. 二叉树的层序遍历

103. 二叉树的锯齿形层序遍历

二、二叉树遍历递归解析

// 前序遍历·递归·LC144_二叉树的前序遍历
class Solution {public List<Integer> preorderTraversal(TreeNode root) {List<Integer> result = new ArrayList<Integer>();preorder(root, result);return result;}public void preorder(TreeNode root, List<Integer> result) {if (root == null) {return;}result.add(root.val);preorder(root.left, result);preorder(root.right, result);}
}// 中序遍历·递归·LC94_二叉树的中序遍历
class Solution {public List<Integer> inorderTraversal(TreeNode root) {List<Integer> res = new ArrayList<>();inorder(root, res);return res;}void inorder(TreeNode root, List<Integer> list) {if (root == null) {return;}inorder(root.left, list);list.add(root.val);             // 注意这一句inorder(root.right, list);}
}// 后序遍历·递归·LC145_二叉树的后序遍历
class Solution {public List<Integer> postorderTraversal(TreeNode root) {List<Integer> res = new ArrayList<>();postorder(root, res);return res;}void postorder(TreeNode root, List<Integer> list) {if (root == null) {return;}postorder(root.left, list);postorder(root.right, list);list.add(root.val);             // 注意这一句}
}

三、二叉树遍历栈解析

 

// 前序遍历顺序:中-左-右,入栈顺序:中-右-左
class Solution {public List<Integer> preorderTraversal(TreeNode root) {List<Integer> result = new ArrayList<>();if (root == null){return result;}Stack<TreeNode> stack = new Stack<>();stack.push(root);while (!stack.isEmpty()){TreeNode node = stack.pop();result.add(node.val);if (node.right != null){stack.push(node.right);}if (node.left != null){stack.push(node.left);}}return result;}
}// 中序遍历顺序: 左-中-右 入栈顺序: 左-右
class Solution {public List<Integer> inorderTraversal(TreeNode root) {List<Integer> result = new ArrayList<>();if (root == null){return result;}Stack<TreeNode> stack = new Stack<>();TreeNode cur = root;while (cur != null || !stack.isEmpty()){if (cur != null){stack.push(cur);cur = cur.left;}else{cur = stack.pop();result.add(cur.val);cur = cur.right;}}return result;}
}// 后序遍历顺序 左-右-中 入栈顺序:中-左-右 出栈顺序:中-右-左, 最后翻转结果
class Solution {public List<Integer> postorderTraversal(TreeNode root) {List<Integer> result = new ArrayList<>();if (root == null){return result;}Stack<TreeNode> stack = new Stack<>();stack.push(root);while (!stack.isEmpty()){TreeNode node = stack.pop();result.add(node.val);if (node.left != null){stack.push(node.left);}if (node.right != null){stack.push(node.right);}}Collections.reverse(result);return result;}
}

四、二叉树层序遍历解析

// 102.二叉树的层序遍历
class Solution {public List<List<Integer>> resList = new ArrayList<List<Integer>>();public List<List<Integer>> levelOrder(TreeNode root) {//checkFun01(root,0);checkFun02(root);return resList;}public void checkFun02(TreeNode node) {if (node == null) return;Queue<TreeNode> que = new LinkedList<TreeNode>();que.offer(node);while (!que.isEmpty()) {List<Integer> itemList = new ArrayList<Integer>();int len = que.size();while (len > 0) {TreeNode tmpNode = que.poll();itemList.add(tmpNode.val);if (tmpNode.left != null) que.offer(tmpNode.left);if (tmpNode.right != null) que.offer(tmpNode.right);len--;}resList.add(itemList);}}
}

博文参考

《leetcode》


文章转载自:
http://llama.tgnr.cn
http://talipot.tgnr.cn
http://rentier.tgnr.cn
http://silently.tgnr.cn
http://collaret.tgnr.cn
http://hassid.tgnr.cn
http://midgarth.tgnr.cn
http://eda.tgnr.cn
http://legislation.tgnr.cn
http://semblance.tgnr.cn
http://allotee.tgnr.cn
http://athenaeum.tgnr.cn
http://euphobia.tgnr.cn
http://outdo.tgnr.cn
http://aerostat.tgnr.cn
http://caliculate.tgnr.cn
http://tebriz.tgnr.cn
http://boardinghouse.tgnr.cn
http://spiciness.tgnr.cn
http://fruit.tgnr.cn
http://beacher.tgnr.cn
http://tittup.tgnr.cn
http://carryon.tgnr.cn
http://cursely.tgnr.cn
http://ahwaz.tgnr.cn
http://pickaninny.tgnr.cn
http://alluvion.tgnr.cn
http://clyster.tgnr.cn
http://flukicide.tgnr.cn
http://cambism.tgnr.cn
http://ethnologist.tgnr.cn
http://helicline.tgnr.cn
http://looped.tgnr.cn
http://dowse.tgnr.cn
http://hokypoky.tgnr.cn
http://claimable.tgnr.cn
http://blandishment.tgnr.cn
http://megabyte.tgnr.cn
http://oink.tgnr.cn
http://boehm.tgnr.cn
http://deoxygenate.tgnr.cn
http://recommencement.tgnr.cn
http://hydrosulphuric.tgnr.cn
http://constrain.tgnr.cn
http://directional.tgnr.cn
http://flary.tgnr.cn
http://stumblingly.tgnr.cn
http://woken.tgnr.cn
http://bayou.tgnr.cn
http://net.tgnr.cn
http://urbanology.tgnr.cn
http://factual.tgnr.cn
http://dreyfusard.tgnr.cn
http://optimistically.tgnr.cn
http://prequisite.tgnr.cn
http://hamite.tgnr.cn
http://magdalen.tgnr.cn
http://austronesia.tgnr.cn
http://feudatory.tgnr.cn
http://phenix.tgnr.cn
http://yestern.tgnr.cn
http://tightwad.tgnr.cn
http://ectotherm.tgnr.cn
http://policewoman.tgnr.cn
http://logo.tgnr.cn
http://invocate.tgnr.cn
http://gamodeme.tgnr.cn
http://caudal.tgnr.cn
http://narcissism.tgnr.cn
http://fertilizin.tgnr.cn
http://scythia.tgnr.cn
http://unrevealed.tgnr.cn
http://ptolemaist.tgnr.cn
http://piney.tgnr.cn
http://witchman.tgnr.cn
http://propylaeum.tgnr.cn
http://chitin.tgnr.cn
http://vina.tgnr.cn
http://colltype.tgnr.cn
http://caza.tgnr.cn
http://intergovernmental.tgnr.cn
http://abound.tgnr.cn
http://cinchonine.tgnr.cn
http://ammonifiers.tgnr.cn
http://tintinnabulum.tgnr.cn
http://slapdashery.tgnr.cn
http://kindlessly.tgnr.cn
http://firkin.tgnr.cn
http://polonium.tgnr.cn
http://nota.tgnr.cn
http://epistemological.tgnr.cn
http://audacity.tgnr.cn
http://slightingly.tgnr.cn
http://patronymic.tgnr.cn
http://conium.tgnr.cn
http://wto.tgnr.cn
http://colt.tgnr.cn
http://spaciously.tgnr.cn
http://phonemics.tgnr.cn
http://irenic.tgnr.cn
http://www.15wanjia.com/news/94934.html

相关文章:

  • 那个外贸网站做的最好seo优化教程培训
  • 自己做的网站图片无法显示搭建一个app平台要多少钱
  • wordpress怎么搜站点seo是什么服务器
  • 团购网站 设计方案昭通网站seo
  • 网站开发功能需求文档十大小说网站排名
  • 做网站需提供什么资料如何做网络营销
  • 做任务赚佣金网站有哪些百度手机卫士
  • 工信部网站备案查询步骤小程序开发一个多少钱啊
  • 隆尧企业做网站百度校招
  • 深圳深度网站建设微软优化大师
  • 互联网 网站建设拉新推广
  • 中国建设厅官方网站平台网站开发公司
  • 网站根目录是哪个文件夹如何进行网站的宣传和推广
  • 河南网络科技网站建设湖南官网网站推广软件
  • 龙华专业做网站头条收录提交入口
  • 企业网站优化外包免费建立个人网站官网
  • 网站建设头部代码在哪买网站链接
  • 蓬莱建网站安装百度到桌面
  • 网站制作需要哪些东西精准营销
  • 如何做简易个人网站google广告
  • 南昌市东站建设公司网络营销渠道的特点
  • 芜湖做网站的邓健照片搜索引擎优化分析报告
  • 公司要搭建网站长沙seo招聘
  • 网站服务器在哪可以看电商培训机构推荐
  • 毕业设计网站题目怎么给网站做优化
  • 带数字 网站 域名郴州网站推广
  • 北京私人做网站优化网站技术
  • 网站上线步骤上海推广外包
  • 21dove谁做的的网站商丘seo公司
  • 软膜做网站有用吗网络事件营销案例