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

公司外贸网站怎么做17zwd一起做业网站

公司外贸网站怎么做,17zwd一起做业网站,手机做网站自己做,WordPress全站广告输入两个整数序列#xff0c;第一个序列表示栈的压入顺序#xff0c;请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如#xff0c;序列 {1,2,3,4,5} 是某栈的压栈序列#xff0c;序列 {4,5,3,2,1} 是该压栈序列对应的一个弹出序列#xff0c;但…输入两个整数序列第一个序列表示栈的压入顺序请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如序列 {1,2,3,4,5} 是某栈的压栈序列序列 {4,5,3,2,1} 是该压栈序列对应的一个弹出序列但 {4,3,5,1,2} 就不可能是该压栈序列的弹出序列。 示例 1 输入pushed [1,2,3,4,5], popped [4,5,3,2,1] 输出true 解释我们可以按以下顺序执行 push(1), push(2), push(3), push(4), pop() - 4, push(5), pop() - 5, pop() - 3, pop() - 2, pop() - 1 示例 2 输入pushed [1,2,3,4,5], popped [4,3,5,1,2] 输出false 解释1 不能在 2 之前弹出。   提示 0 pushed.length popped.length 1000 0 pushed[i], popped[i] 1000 pushed 是 popped 的排列。 思路模拟每压入一个就尝试弹出到不能再弹。到最后栈空就可以。 class Solution {public boolean validateStackSequences(int[] pushed, int[] popped) {StackInteger stack new StackInteger();int j 0;for(int i 0;i pushed.length;i){stack.push(pushed[i]);while(!stack.empty() stack.peek() popped[j]){stack.pop();j;}}return stack.empty();} } 从上到下打印出二叉树的每个节点同一层的节点按照从左到右的顺序打印。 例如: 给定二叉树: [3,9,20,null,null,15,7], 3    / \   9  20     /  \    15   7 返回 [3,9,20,15,7]   提示 节点总数 1000 思路层序遍历出队列时用另一个list记录最后转为数组即可。 /*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode(int x) { val x; }* }*/ class Solution {public int[] levelOrder(TreeNode root) {if (root null) return new int[0];QueueTreeNode queue new LinkedList();ListInteger res new ArrayList();queue.add(root);while(!queue.isEmpty()) {TreeNode node queue.poll();res.add(node.val);if(node.left ! null) queue.add(node.left);if(node.right ! null) queue.add(node.right);}int[] _result new int[res.size()];for (int i 0; i res.size(); i) {_result[i] res.get(i);}return _result;} } 从上到下按层打印二叉树同一层的节点按从左到右的顺序打印每一层打印到一行。 例如: 给定二叉树: [3,9,20,null,null,15,7], 3    / \   9  20     /  \    15   7 返回其层次遍历结果 [   [3],   [9,20],   [15,7] ]   提示 节点总数 1000 思路遍历时一次弹完一层所有节点队列内当时的所有节点并用一个list保存。 /*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode(int x) { val x; }* }*/ class Solution {public ListListInteger levelOrder(TreeNode root) {QueueTreeNode queue new LinkedList();ListListInteger res new ArrayList();if(root ! null) queue.add(root);while(!queue.isEmpty()) {ListInteger tmp new ArrayList();for(int i queue.size(); i 0; i--) {TreeNode node queue.poll();tmp.add(node.val);if(node.left ! null) queue.add(node.left);if(node.right ! null) queue.add(node.right);}res.add(tmp);}return res;} } 请实现一个函数按照之字形顺序打印二叉树即第一行按照从左到右的顺序打印第二层按照从右到左的顺序打印第三行再按照从左到右的顺序打印其他行以此类推。 例如: 给定二叉树: [3,9,20,null,null,15,7], 3    / \   9  20     /  \    15   7 返回其层次遍历结果 [   [3],   [20,9],   [15,7] ]   提示 节点总数 1000 思路和上题一样只不过加一句话翻转部分temp。 /*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode(int x) { val x; }* }*/ class Solution {public ListListInteger levelOrder(TreeNode root) {QueueTreeNode queue new LinkedList();ListListInteger res new ArrayList();if(root ! null) queue.add(root);while(!queue.isEmpty()) {ListInteger tmp new ArrayList();for(int i queue.size(); i 0; i--) {TreeNode node queue.poll();tmp.add(node.val);if(node.left ! null) queue.add(node.left);if(node.right ! null) queue.add(node.right);}if(res.size() % 2 1) Collections.reverse(tmp);res.add(tmp);}return res;} }
http://www.sadfv.cn/news/102503/

相关文章:

  • 博客论坛网站开发58同城买房网
  • 怎么做58同城网站教程建设通和天眼查网站
  • 做母婴网站赚钱网站业务维护
  • 网站备案后证书正能量免费软件
  • 杭州网站建设公司推荐卡片形式的网站
  • 微信打赏wordpressseo排名工具哪个好
  • 山东网站制作哪家好陈塘庄网站建设
  • 深圳网站建设微赢天下做简历的什么客网站
  • 网站建设中的智能元素深圳做小程序网站设计
  • 蔚县网站建设wl17581百度热门关键词排名
  • 优秀的网站设计分析佛山网站设计多少钱
  • 营销加盟网站建设WordPress小工具是什么
  • 百度我的网站网页图片制作
  • 网站建设绵阳辉煌电商怎么制作自己的网页网站首页
  • 网站开发计划时间手递手个人求职信息网
  • 公司合法网站域名怎么注册国外ui界面设计网站
  • 深圳四站合一网站建设重庆企业网站推广公司
  • 海外购物网站排名千库网app官方下载
  • 重庆 网站设计外包公司深圳手机端网站建设专业
  • 大学教学应用网站开发现状泉州手机网站建设费用
  • 工程建设标准化网站设计专业考研平面素材网站
  • 建设高流量网站网页设计尺寸标准
  • 网站怎么换模板百度帐号管家
  • 销售型网站的建设流程及特点班级网站建设流程步骤
  • 贵州省建设厅实名认证网站免费个人网站注册
  • 哪个网站可以做字体网站建设与管理专业实训室
  • 专门做外卖的网站网站的建设论文
  • 微网站制作电话哪些网站能够免费做公考题
  • 网站设计与建设代码苏州建筑公司排名
  • 睢宁建网站关键词优化报价