/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param root TreeNode类 
     * @return int整型
     */
    int run(TreeNode* root) {
        if(root==nullptr){
            return 0;
        }
        if(root->left==nullptr&&root->right==nullptr){
            return 1;
        }
        int l=run(root->left);
        int r=run(root->right);
        int ans;
        if(l==0){
            ans=r;
        }
        else if(r==0){
            ans=l;
        }
        else{
            ans=l<r?l:r;
        }
        return ans+1;
    }
};