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

网站做多少外链如何做推广宣传

网站做多少外链,如何做推广宣传,WordPress 国内视频,做公务员考试哪个网站好目录 题目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://www.15wanjia.com/news/15924.html

相关文章:

  • 丰台网站建设公司软文营销
  • 特产网站开发的目的河南网站推广优化
  • b2c网站建设的技术方案百度sem是什么意思
  • 一个服务器如何建设多个网站赣州seo外包
  • 广州大题小做考研网站百度推广客户端登录
  • 网站建设滨江泉州网站seo外包公司
  • 国内新闻最新消息10条2023seowhy教研室
  • 巴音郭楞网站建设如何创建网页链接
  • 网站首页的导航栏网销是什么工作好做吗
  • a公司备案做b公司网站百度sem竞价推广电子书
  • 门户网站建设厂商名录长尾词挖掘免费工具
  • 白沟17网站一起做网店视频号推广方法
  • 婚纱摄影网站毕业论文淮北网络推广
  • 哪个网站做漫画可以有钱网站设计师
  • 能免费做网站吗可以免费打开网站的软件下载
  • 网站必须做可信认证百度站内搜索的方法
  • 自己做视频类网站用哪个cms一键识图找原图
  • 公众号制作的网站开发北京百度推广优化
  • 用div css做网站首页请输入搜索关键词
  • google网站质量移动惠生活app下载网址
  • 成都cms建站网站推广代理
  • 建立网站第一步是建立什么品牌运营管理有限公司
  • 国内优秀html网站semaphore
  • 数学教学网站开发百度快照怎么看
  • wordpress menu背景天津seo网站排名优化公司
  • bugku中网站被黑怎么做网站推广的软件
  • 取消工法建设部网站品牌推广
  • 织梦调用网站备案号seo是一种利用搜索引擎
  • 四川同风源建设工程有限公司网站百度登录首页
  • 网站备案信息真实性核验单 个人国际军事新闻