首页 > 图灵资讯 > 技术篇>正文

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); }}

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

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