Trees

Treversals

Estimated reading: 1 minute 28 views

 Binary Tree Inorder Traversal

				
					  public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        inorderHelper(root, result);
        return result;
    }
    
 private void inorderHelper(TreeNode node, List<Integer> result) {
        if (node == null) {
            return;
        }
        // Traverse left subtree
        inorderHelper(node.left, result);
        // Visit root
        result.add(node.val);
        // Traverse right subtree
        inorderHelper(node.right, result);
    }
				
			
Share this Doc

Treversals

Or copy link

CONTENTS