class TreeNode{
public $left;
public $right;
public $val;
public function __construct($val){
$this->val=$val;
}
}
function TreeMinDepth($pRoot){
if(null===$pRoot){
return 0;
}
$leftMinDepth=TreeMinDepth($pRoot->left)+1;
$rightMinDepth=TreeMinDepth($pRoot->right)+1;
if(null!==$pRoot->left && null!==$pRoot->right){
return ($leftMinDepth<$rightMinDepth)?$leftMinDepth:$rightMinDepth;
}else{
return ($leftMinDepth<$rightMinDepth)?$rightMinDepth:$leftMinDepth;
}
}