import java.util.*;

/*
 * public class TreeNode {
 *   int val = 0;
 *   TreeNode left = null;
 *   TreeNode right = null;
 * }
 */

public class Solution {
    /**
     * 
     * @param root TreeNode类 
     * @return int整型
     */
    public int run (TreeNode root) {
        // write code here
        if (null==root){
            return 0;
        }

        if(null==root.left){
            return run(root.right)+1;
        }

        if(null==root.right){
            return run(root.left)+1;
        }

        return Math.min(run(root.left),run(root.right))+1;
    }
}