diff --git a/leetcode/104.php b/leetcode/104.php index 0f87008..a7bcc36 100644 --- a/leetcode/104.php +++ b/leetcode/104.php @@ -36,6 +36,15 @@ function one($root) { return $root === null ? 0 : max( $this->one( $root->left ), $this->one( $root->right ) ) + 1; } + + function two($root){ + if (!$root){ + return 0; + } + $left = $this->maxDepth( $root->left ); + $right = $this->maxDepth( $root->right ); + return max($left,$right)+1; + } } $a = new TreeNode( 3 ); diff --git a/leetcode/50.php b/leetcode/50.php new file mode 100644 index 0000000..63d84ef --- /dev/null +++ b/leetcode/50.php @@ -0,0 +1,39 @@ +size( $x, $n ); + return $size; + } + + function size($x, $n) + { + if ($n == 1) { + return $x; + } + $size = $this->size( $x, floor( $n / 2 ) ); + return $n % 2 ? $size * $size * $x : $size * $size; + } +} + +$x = 2; +$n = 3; +$solution = new Solution(); +$b = $solution->myPow( $x, $n ); +var_dump( $b ); \ No newline at end of file