diff --git a/solution/0100-0199/0100.Same Tree/README.md b/solution/0100-0199/0100.Same Tree/README.md index 5231442dc63c2..982f79d32854a 100644 --- a/solution/0100-0199/0100.Same Tree/README.md +++ b/solution/0100-0199/0100.Same Tree/README.md @@ -566,6 +566,43 @@ impl Solution { } ``` +### **PHP** + +```php +/** + * Definition for a binary tree node. + * class TreeNode { + * public $val = null; + * public $left = null; + * public $right = null; + * function __construct($val = 0, $left = null, $right = null) { + * $this->val = $val; + * $this->left = $left; + * $this->right = $right; + * } + * } + */ +class Solution { + /** + * @param TreeNode $p + * @param TreeNode $q + * @return Boolean + */ + function isSameTree($p, $q) { + if ($p == Null && $q == Null) { + return true; + } + if ($p == Null || $q == Null) { + return false; + } + if ($p->val != $q->val) { + return false; + } + return $this->isSameTree($p->left, $q->left) && $this->isSameTree($p->right, $q->right); + } +} +``` + ### **...** ``` diff --git a/solution/0100-0199/0100.Same Tree/README_EN.md b/solution/0100-0199/0100.Same Tree/README_EN.md index 14d2571faeedd..d83a6de06deb4 100644 --- a/solution/0100-0199/0100.Same Tree/README_EN.md +++ b/solution/0100-0199/0100.Same Tree/README_EN.md @@ -538,6 +538,43 @@ impl Solution { } ``` +### **PHP** + +```php +/** + * Definition for a binary tree node. + * class TreeNode { + * public $val = null; + * public $left = null; + * public $right = null; + * function __construct($val = 0, $left = null, $right = null) { + * $this->val = $val; + * $this->left = $left; + * $this->right = $right; + * } + * } + */ +class Solution { + /** + * @param TreeNode $p + * @param TreeNode $q + * @return Boolean + */ + function isSameTree($p, $q) { + if ($p == Null && $q == Null) { + return true; + } + if ($p == Null || $q == Null) { + return false; + } + if ($p->val != $q->val) { + return false; + } + return $this->isSameTree($p->left, $q->left) && $this->isSameTree($p->right, $q->right); + } +} +``` + ### **...** ``` diff --git a/solution/0100-0199/0100.Same Tree/Solution.php b/solution/0100-0199/0100.Same Tree/Solution.php new file mode 100644 index 0000000000000..859d927d7723b --- /dev/null +++ b/solution/0100-0199/0100.Same Tree/Solution.php @@ -0,0 +1,32 @@ +/** + * Definition for a binary tree node. + * class TreeNode { + * public $val = null; + * public $left = null; + * public $right = null; + * function __construct($val = 0, $left = null, $right = null) { + * $this->val = $val; + * $this->left = $left; + * $this->right = $right; + * } + * } + */ +class Solution { + /** + * @param TreeNode $p + * @param TreeNode $q + * @return Boolean + */ + function isSameTree($p, $q) { + if ($p == Null && $q == Null) { + return true; + } + if ($p == Null || $q == Null) { + return false; + } + if ($p->val != $q->val) { + return false; + } + return $this->isSameTree($p->left, $q->left) && $this->isSameTree($p->right, $q->right); + } +} \ No newline at end of file