/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * }; */ class Solution { public: int run(TreeNode* root) { // write code here if(root==nullptr) return 0; int l = run(root->left)+1; int r = run(root->right)+1; if(l>1&&r>1) return min(l, r); else return max(l,r); } };