Likou 94 In-order traversal of binary tree (recursive realization)

1. In-order traversal of binary tree

Insert picture description here

2. My initial thoughts and problems

Slightly, look directly at the idea and solution of force buckle
Insert picture description here

3. Problem solving method one: recursion

class Solution {
    
    
    public List<Integer> inorderTraversal(TreeNode root) {
    
    
        List<Integer> res = new ArrayList<Integer>();
        inorder(root, res);
        return res;
    }

    public void inorder(TreeNode root, List<Integer> res) {
    
    
        if (root == null) {
    
    
            return;
        }
        inorder(root.left, res);
        res.add(root.val);
        inorder(root.right, res);
    }
}

Insert picture description here

Guess you like

Origin blog.csdn.net/ambitionLlll/article/details/114330932