LeetCode面试题:二叉树的中序遍历

发布时间:2023-05-12 10:16:29

  1.简述:

  给出二叉树根节点rot,返回其中序遍历。

  示例 1:

#yyds干货盘点# LeetCode面试题:二叉树的中序遍历_二叉树

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

  示例 2: 输入:root = []输出:[]

  示例 3: 输入:root = [1]输出:[1]

  2.实现代码: class Solution { public List inorderTraversal(TreeNode root) { List res = new ArrayList(); inorder(root, res); return res; } public void inorder(TreeNode root, List res) { if (root == null) { return; } inorder(root.left, res); res.add(root.val); inorder(root.right, res); }}

ps 图灵课堂老师从近一百套最新一线互联网公司面试题中精选而出,涵盖Java架构面试 所有技术栈,包括JVM,Mysql,并发,Spring,Redis,MQ,Zookeeper,Netty, Dubbo,Spring Boot,Spring Cloud,数据结构与算法,设计模式等相关技术领域的大 厂面试题及详解。 详情咨询客服获取全套面经试题。

上一篇 LeetCode程序员面试金典:字符串相乘
下一篇 javafx中style没有刷新,css没有效果

文章素材均来源于网络,如有侵权,请联系管理员删除。

标签: