94. Binary Tree Inorder Traversal(inorder ) ***(to be continue)easy
Posted stiles
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了94. Binary Tree Inorder Traversal(inorder ) ***(to be continue)easy相关的知识,希望对你有一定的参考价值。
Given a binary tree, return the inorder traversal of its nodes‘ values.
Example:
Input: [1,null,2,3] 1 2 / 3 Output: [1,3,2]
Follow up: Recursive solution is trivial, could you do it iteratively?
Recursive solution
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { List<Integer> res = new ArrayList<Integer>(); public List<Integer> inorderTraversal(TreeNode root) { //inorder traveral : left root right inorder( root); return res; } void inorder(TreeNode node){ if(node==null) return; inorder(node.left); res.add(node.val); inorder(node.right); } }
follow up questions
以上是关于94. Binary Tree Inorder Traversal(inorder ) ***(to be continue)easy的主要内容,如果未能解决你的问题,请参考以下文章
94. Binary Tree Inorder Traversal
#Leetcode# 94. Binary Tree Inorder Traversal
(Tree)94.Binary Tree Inorder Traversal
94. Binary Tree Inorder Traversal