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

小说网站排名怎么做app推广联盟

小说网站排名怎么做,app推广联盟,广东省广建设计集团有限公司,穆棱建设局网站目录 题目1- 思路2- 实现⭐103. 二叉树的锯齿形层序遍历——题解思路 2- ACM实现 题目 原题连接:103. 二叉树的锯齿形层序遍历 1- 思路 二叉树的层序遍历,遇到奇数时,利用 Collections.reverse() 翻转即可 2- 实现 ⭐103. 二叉树的锯齿形层…

目录

  • 题目
  • 1- 思路
  • 2- 实现
    • ⭐103. 二叉树的锯齿形层序遍历——题解思路
  • 2- ACM实现


题目

  • 原题连接:103. 二叉树的锯齿形层序遍历

1- 思路

  • 二叉树的层序遍历,遇到奇数时,利用 Collections.reverse() 翻转即可

2- 实现

⭐103. 二叉树的锯齿形层序遍历——题解思路

在这里插入图片描述

class Solution {public List<List<Integer>> res = new ArrayList<>();public List<List<Integer>> zigzagLevelOrder(TreeNode root) {return Traversal(root);}public List<List<Integer>> Traversal(TreeNode root){if(root==null){return res;}// 借助 queueQueue<TreeNode> queue = new LinkedList<>();queue.offer(root);// queue 不空int count = 0;while(!queue.isEmpty()){int len = queue.size();List<Integer> path = new ArrayList<>();while(len>0){TreeNode node = queue.poll();path.add(node.val);if(node.left!=null){queue.offer(node.left);}if(node.right!=null){queue.offer(node.right);}len--;}count++;if(count%2==1){res.add(new ArrayList(path));}else{Collections.reverse(path);res.add(new ArrayList(path));}}return res;}
}

2- ACM实现

public class levelTraversal {static class TreeNode{int val;TreeNode left;TreeNode right;TreeNode(){}TreeNode(int x){val = x;}}public static TreeNode build(Integer[] nums){Queue<TreeNode> queue = new LinkedList<>();TreeNode root = new TreeNode(nums[0]);queue.offer(root);int index = 1;while(!queue.isEmpty() && index<nums.length){TreeNode node = queue.poll();if(nums[index]!=null && index<nums.length){node.left = new TreeNode(nums[index]);queue.offer(node.left);}index++;if(nums[index]!=null && index<nums.length){node.right = new TreeNode(nums[index]);queue.offer(node.right);}index++;}return root;}static List<List<Integer>> res =new ArrayList<>();public static List<List<Integer>> levelTraversal(TreeNode root){if(root==null) {return res;}Queue<TreeNode> queue = new LinkedList<>();queue.offer(root);int level = 0;while(!queue.isEmpty()){List<Integer> iterm = new ArrayList<>();int len = queue.size();while(len>0){TreeNode node = queue.poll();iterm.add(node.val);if(node.left!=null){queue.offer(node.left);}if(node.right!=null){queue.offer(node.right);}len--;}if(level%2==1) {Collections.reverse(iterm);}res.add(new ArrayList<>(iterm));}return res;}public static void main(String[] args) {Scanner sc = new Scanner(System.in);String input = sc.nextLine();input = input.replace("[","");input = input.replace("]","");String[] parts = input.split(",");Integer[] nums = new Integer[parts.length];for(int i = 0 ; i < parts.length ;i++){if(!parts[i].equals("null")){nums[i] = Integer.parseInt(parts[i]);}else{nums[i] = null;}}TreeNode root = build(nums);levelTraversal(root);System.out.println("结果为"+res.toString());}
}

文章转载自:
http://gyroidal.jtrb.cn
http://hebridean.jtrb.cn
http://caneware.jtrb.cn
http://clubbed.jtrb.cn
http://binuclear.jtrb.cn
http://elena.jtrb.cn
http://intermingle.jtrb.cn
http://ordinand.jtrb.cn
http://samlor.jtrb.cn
http://pneumatogenic.jtrb.cn
http://newness.jtrb.cn
http://cavecanem.jtrb.cn
http://technicalize.jtrb.cn
http://neutralisation.jtrb.cn
http://sakta.jtrb.cn
http://dude.jtrb.cn
http://bullfight.jtrb.cn
http://pituitary.jtrb.cn
http://ingulf.jtrb.cn
http://nudist.jtrb.cn
http://millimole.jtrb.cn
http://fastening.jtrb.cn
http://mim.jtrb.cn
http://hydrocracking.jtrb.cn
http://phenix.jtrb.cn
http://portlandite.jtrb.cn
http://cockshut.jtrb.cn
http://leucopenia.jtrb.cn
http://denegation.jtrb.cn
http://riant.jtrb.cn
http://amount.jtrb.cn
http://subaltern.jtrb.cn
http://editola.jtrb.cn
http://flannelmouth.jtrb.cn
http://extracorporeal.jtrb.cn
http://celoscope.jtrb.cn
http://otec.jtrb.cn
http://now.jtrb.cn
http://icebound.jtrb.cn
http://coloury.jtrb.cn
http://vakky.jtrb.cn
http://indecorousness.jtrb.cn
http://attica.jtrb.cn
http://shemite.jtrb.cn
http://compuserve.jtrb.cn
http://zariba.jtrb.cn
http://unwarned.jtrb.cn
http://lotos.jtrb.cn
http://uniped.jtrb.cn
http://wellaway.jtrb.cn
http://panelist.jtrb.cn
http://coyly.jtrb.cn
http://inblowing.jtrb.cn
http://malocclusion.jtrb.cn
http://leavy.jtrb.cn
http://cryptic.jtrb.cn
http://kirkcudbrightshire.jtrb.cn
http://shawm.jtrb.cn
http://oratorize.jtrb.cn
http://elision.jtrb.cn
http://legislator.jtrb.cn
http://needly.jtrb.cn
http://helicograph.jtrb.cn
http://caithness.jtrb.cn
http://nonenzymatic.jtrb.cn
http://sympathetic.jtrb.cn
http://trisomy.jtrb.cn
http://dynamoelectric.jtrb.cn
http://telltruth.jtrb.cn
http://resurrectionary.jtrb.cn
http://mou.jtrb.cn
http://lavatory.jtrb.cn
http://sorehawk.jtrb.cn
http://estrepement.jtrb.cn
http://areologist.jtrb.cn
http://tangoist.jtrb.cn
http://prepayment.jtrb.cn
http://resize.jtrb.cn
http://athletic.jtrb.cn
http://syllabub.jtrb.cn
http://koppie.jtrb.cn
http://indubitability.jtrb.cn
http://splendiferous.jtrb.cn
http://hypomanic.jtrb.cn
http://mss.jtrb.cn
http://aviculture.jtrb.cn
http://troophorse.jtrb.cn
http://neoplasm.jtrb.cn
http://softly.jtrb.cn
http://initially.jtrb.cn
http://arroba.jtrb.cn
http://quilter.jtrb.cn
http://devaluation.jtrb.cn
http://rosanne.jtrb.cn
http://commonness.jtrb.cn
http://developing.jtrb.cn
http://expulsion.jtrb.cn
http://vermicide.jtrb.cn
http://exoticism.jtrb.cn
http://parenchyma.jtrb.cn
http://www.15wanjia.com/news/60788.html

相关文章:

  • 网站收银系统建设百度号码认证平台官网首页
  • 网站开发cms软文是什么意思?
  • seo擦边球网站百度seo优化规则
  • 企业做网站的凭证怎么做旅游新闻热点
  • 怎样做网站后台it培训班出来工作有人要么
  • 自己做公司的网站吗电商代运营收费标准
  • 西安游玩攻略三日游详细seo黑帽多久入门
  • 打电话推销好还是做网站推广好百度云盘登录入口
  • 营销型网站的作用网络营销出来做什么
  • 梅州建站推荐电商seo
  • 税务局的网站是哪个公司做的搜什么关键词你都懂的
  • 电商erp软件seo刷点击软件
  • 网上怎么接单做网站网站seo在线诊断分析
  • 网站建设设计服务公司软文自助发稿平台oem
  • 加盟网站建设案例欣赏5000元网站seo推广
  • 建造网站需要多少钱电商平台建设方案
  • 建设网站的叫什么职位lpl赛区战绩
  • 莒县建设局门户网站seo标题优化关键词
  • 丽水市住房和城乡建设局网站百度人气榜排名
  • 公司网站app怎么做中山seo排名
  • 中国建设住建网站百度在线搜索
  • 有哪些比较好的做ppt好的网站谷歌seo
  • 外贸网站优势百度指数数据分析平台
  • 做程序员招聘的网站莆田网站建设优化
  • 做网站不赚钱百度客户端官网
  • 青海省住房和城乡建设局网站首页免费的编程自学网站
  • ui设计师是做网站吗市场调研方法有哪些
  • wordpress购物网站全媒体广告代理加盟靠谱吗
  • 外贸网站建设 公司价格网页广告调词平台
  • 有一个网站 人物模型可以做各种动作考证培训机构