Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d7251b1

Browse files
committed
Add solution 125.
1 parent f1b03ce commit d7251b1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
3+
/**
4+
* @param String $s
5+
* @return Boolean
6+
*/
7+
function isPalindrome($s) {
8+
if ($s == null || strlen($s) < 2) return true;
9+
10+
for ($i = 0, $j = strlen($s) -1; $i < $j; ) {
11+
if (self::normalizeChar($s[$i]) == ' ') $i++;
12+
else if (self::normalizeChar($s[$j]) == ' ') $j--;
13+
else if (self::normalizeChar($s[$i++]) != self::normalizeChar($s[$j--]))
14+
return false;
15+
}
16+
17+
return true;
18+
}
19+
20+
function normalizeChar($c) {
21+
if (ord($c) > 96 && ord($c) < 123 || ord($c) > 47 && ord($c) < 58) return $c;
22+
if (ord($c) > 64 && ord($c) < 91) return chr(ord($c) + 32);
23+
return ' ';
24+
}
25+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /