Skip to content

Commit 105b453

Browse files
authored
feat: add php solution to lc problem: No.0125 (#951)
1 parent 3041b33 commit 105b453

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

solution/0100-0199/0125.Valid Palindrome/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,30 @@ func verify(ch byte) bool {
308308
}
309309
```
310310

311+
### **PHP**
312+
313+
```php
314+
class Solution {
315+
/**
316+
* @param String $s
317+
* @return Boolean
318+
*/
319+
function isPalindrome($s) {
320+
$regex = "/[a-z0-9]/";
321+
$s = strtolower($s);
322+
preg_match_all($regex, $s, $matches);
323+
if ($matches[0] == Null) return true;
324+
$len = floor(count($matches[0]) / 2);
325+
for ($i = 0; $i < $len; $i++) {
326+
if ($matches[0][$i] != $matches[0][count($matches[0]) - 1 - $i]) {
327+
return false;
328+
}
329+
}
330+
return true;
331+
}
332+
}
333+
```
334+
311335
### **...**
312336

313337
```

solution/0100-0199/0125.Valid Palindrome/README_EN.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,30 @@ func verify(ch byte) bool {
296296
}
297297
```
298298

299+
### **PHP**
300+
301+
```php
302+
class Solution {
303+
/**
304+
* @param String $s
305+
* @return Boolean
306+
*/
307+
function isPalindrome($s) {
308+
$regex = "/[a-z0-9]/";
309+
$s = strtolower($s);
310+
preg_match_all($regex, $s, $matches);
311+
if ($matches[0] == Null) return true;
312+
$len = floor(count($matches[0]) / 2);
313+
for ($i = 0; $i < $len; $i++) {
314+
if ($matches[0][$i] != $matches[0][count($matches[0]) - 1 - $i]) {
315+
return false;
316+
}
317+
}
318+
return true;
319+
}
320+
}
321+
```
322+
299323
### **...**
300324

301325
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
/**
3+
* @param String $s
4+
* @return Boolean
5+
*/
6+
function isPalindrome($s) {
7+
$regex = "/[a-z0-9]/";
8+
$s = strtolower($s);
9+
preg_match_all($regex, $s, $matches);
10+
if ($matches[0] == Null) return true;
11+
$len = floor(count($matches[0]) / 2);
12+
for ($i = 0; $i < $len; $i++) {
13+
if ($matches[0][$i] != $matches[0][count($matches[0]) - 1 - $i]) {
14+
return false;
15+
}
16+
}
17+
return true;
18+
}
19+
}

0 commit comments

Comments
 (0)