Movatterモバイル変換


[0]ホーム

URL:


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

Commita7361d2

Browse files
authored
Merge pull requestneetcode-gh#103 from ediazmen/Exercise-125
JS 125-Valid-Palindrome
2 parents32ccc97 +644487b commita7361d2

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

‎javascript/125-Valid-Palindrome.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ var isPalindrome = function(s) {
1616
j--
1717
}
1818
returntrue;
19-
};
19+
};

‎javascript/125-ValidPalindrome.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
classisValidPalindrome{
2+
constructor(string){
3+
this.string=string;
4+
}
5+
isPalindrome(string){
6+
letleft=0;
7+
letright=string.length-1;
8+
while(left<right){
9+
while(left<right&&this.isAlphaNumeric(string[left])){
10+
left++
11+
}
12+
while(right>left&&this.isAlphaNumeric(string[right])){
13+
right--
14+
}
15+
if(string[left].toLowerCase()!=string[right].toLowerCase()){
16+
returnfalse;
17+
}
18+
left++
19+
right--
20+
}
21+
returntrue
22+
}
23+
24+
isAlphaNumeric(c){
25+
return('A'.charCodeAt(0)<=c.charCodeAt(0)<='Z'.charCodeAt(0)||
26+
'a'.charCodeAt(0)<=c.charCodeAt(0)<='z'.charCodeAt(0)||
27+
'0'.charCodeAt(0)<=c.charCodeAt(0)<='9'.charCodeAt(0))
28+
}
29+
30+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp