5 lines C colution; 4ms;

  • 0
    typedef struct TreeNode tn;
    int minDepth(tn* root)
      if(!root) return 0;
      if(!root->left)         return (!root->right)? 1 : minDepth(root->right) +1;
      else if(!root->right)   return minDepth(root->left) +1;
      int lMin, rMin;
      return ((lMin = minDepth(root->left)) <  (rMin =minDepth(root->right)))? lMin+1 : rMin+1;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.