Binary Tree Inorder Traversal Leetcode Solution

Hello Coders, Today, I give another solution for the Leetcode problem which is ” Binary Tree Inorder Traversal Leetcode Solution “.

But before moving on to the solution, let’s take a look at the problem statement.

Problem statement:

Given the root of a binary tree, return the inorder traversal of its nodes’ values.

Example 1:

Input: root = [1,null,2,3]
Output: [1,3,2]

Example 2:

Input: root = []
Output: []

Example 3:

Input: root = [1]
Output: [1]

//Binary Tree Inorder Traversal Leetcode Solution

class Solution {
    public List<Integer> inorderTraversal(TreeNode root) {
       List<Integer> l=new ArrayList<Integer>();
        
        return btit(root,l);
        
    }
    
    public List<Integer> btit(TreeNode root, List<Integer> l){
        if(root==null){
            return l;
        }
        btit(root.left,l);
        l.add(root.val);
        btit(root.right,l);
        return l;
    }
    
    
}

//Binary Tree Inorder Traversal Leetcode Solution

Disclaimer: This problem(Binary Tree Inorder Traversal Leetcode solution) is originally created by Leetcode. Codesagar only provides a solution for it. This solution is only for Educational and learning purposes.

Leave a Comment