From 3f6e1f790ed395120135f5f258675e628b4261d9 Mon Sep 17 00:00:00 2001 From: Qiu-IT Date: Tue, 14 Mar 2023 13:47:55 +0100 Subject: [PATCH 1/4] feat: add php solution to lc problem: No.s0100 --- solution/0100-0199/0100.Same Tree/README.md | 36 ++++++++++++++++++ .../0100-0199/0100.Same Tree/README_EN.md | 37 +++++++++++++++++++ .../0100-0199/0100.Same Tree/Solution.php | 32 ++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 solution/0100-0199/0100.Same Tree/Solution.php diff --git a/solution/0100-0199/0100.Same Tree/README.md b/solution/0100-0199/0100.Same Tree/README.md index 5231442dc63c2..724f979b7b251 100644 --- a/solution/0100-0199/0100.Same Tree/README.md +++ b/solution/0100-0199/0100.Same Tree/README.md @@ -565,6 +565,42 @@ 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..11a698b1650e2 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..10d97f4f94279 --- /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 From ef6a4044f19bee7d2a5a4a562ce7d3975f227232 Mon Sep 17 00:00:00 2001 From: Qiu-IT Date: Tue, 14 Mar 2023 17:36:44 +0100 Subject: [PATCH 2/4] add solution --- solution/0100-0199/0100.Same Tree/README.md | 4 ++-- solution/0100-0199/0100.Same Tree/README_EN.md | 4 ++-- solution/0100-0199/0100.Same Tree/Solution.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/solution/0100-0199/0100.Same Tree/README.md b/solution/0100-0199/0100.Same Tree/README.md index 724f979b7b251..9f634400ad38e 100644 --- a/solution/0100-0199/0100.Same Tree/README.md +++ b/solution/0100-0199/0100.Same Tree/README.md @@ -594,10 +594,10 @@ class Solution { if ($p == Null || $q == Null) { return false; } - if ($p - > val != $q - > val) { + if ($p -> val != $q -> val) { return false; } - return $this - > isSameTree($p - > left, $q - > left) && $this - > isSameTree($p - > right, $q - > right); + 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 11a698b1650e2..9b22d2093b8fe 100644 --- a/solution/0100-0199/0100.Same Tree/README_EN.md +++ b/solution/0100-0199/0100.Same Tree/README_EN.md @@ -567,10 +567,10 @@ class Solution { if ($p == Null || $q == Null) { return false; } - if ($p - > val != $q - > val) { + if ($p -> val != $q -> val) { return false; } - return $this - > isSameTree($p - > left, $q - > left) && $this - > isSameTree($p - > right, $q - > right); + 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 index 10d97f4f94279..d170feea9ac14 100644 --- a/solution/0100-0199/0100.Same Tree/Solution.php +++ b/solution/0100-0199/0100.Same Tree/Solution.php @@ -24,9 +24,9 @@ function isSameTree($p, $q) { if ($p == Null || $q == Null) { return false; } - if ($p - > val != $q - > val) { + if ($p -> val != $q -> val) { return false; } - return $this - > isSameTree($p - > left, $q - > left) && $this - > isSameTree($p - > right, $q - > right); + return $this -> isSameTree($p -> left, $q -> left) && $this -> isSameTree($p -> right, $q -> right); } } \ No newline at end of file From f0cfb71cc6ce64e1ffe42b996b1a956eb8f0d7f6 Mon Sep 17 00:00:00 2001 From: Qiu-IT Date: Tue, 14 Mar 2023 17:42:20 +0100 Subject: [PATCH 3/4] add README --- solution/0100-0199/0100.Same Tree/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/solution/0100-0199/0100.Same Tree/README.md b/solution/0100-0199/0100.Same Tree/README.md index 9f634400ad38e..e109303e53c09 100644 --- a/solution/0100-0199/0100.Same Tree/README.md +++ b/solution/0100-0199/0100.Same Tree/README.md @@ -565,6 +565,7 @@ impl Solution { } } ``` + ### **PHP** ```php From cb4c84cbb46ff666222ce1bca6a4c649545983f3 Mon Sep 17 00:00:00 2001 From: Qiu-IT Date: Thu, 16 Mar 2023 10:45:56 +0100 Subject: [PATCH 4/4] third commit --- solution/0100-0199/0100.Same Tree/README.md | 6 +++--- solution/0100-0199/0100.Same Tree/README_EN.md | 4 ++-- solution/0100-0199/0100.Same Tree/Solution.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/solution/0100-0199/0100.Same Tree/README.md b/solution/0100-0199/0100.Same Tree/README.md index e109303e53c09..982f79d32854a 100644 --- a/solution/0100-0199/0100.Same Tree/README.md +++ b/solution/0100-0199/0100.Same Tree/README.md @@ -595,12 +595,12 @@ class Solution { if ($p == Null || $q == Null) { return false; } - if ($p -> val != $q -> val) { + if ($p->val != $q->val) { return false; } - return $this -> isSameTree($p -> left, $q -> left) && $this -> isSameTree($p -> right, $q -> right); + 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 9b22d2093b8fe..d83a6de06deb4 100644 --- a/solution/0100-0199/0100.Same Tree/README_EN.md +++ b/solution/0100-0199/0100.Same Tree/README_EN.md @@ -567,10 +567,10 @@ class Solution { if ($p == Null || $q == Null) { return false; } - if ($p -> val != $q -> val) { + if ($p->val != $q->val) { return false; } - return $this -> isSameTree($p -> left, $q -> left) && $this -> isSameTree($p -> right, $q -> right); + 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 index d170feea9ac14..859d927d7723b 100644 --- a/solution/0100-0199/0100.Same Tree/Solution.php +++ b/solution/0100-0199/0100.Same Tree/Solution.php @@ -24,9 +24,9 @@ function isSameTree($p, $q) { if ($p == Null || $q == Null) { return false; } - if ($p -> val != $q -> val) { + if ($p->val != $q->val) { return false; } - return $this -> isSameTree($p -> left, $q -> left) && $this -> isSameTree($p -> right, $q -> right); + return $this->isSameTree($p->left, $q->left) && $this->isSameTree($p->right, $q->right); } } \ No newline at end of file