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

Commit60c6a15

Browse files
committed
Merge pull requestneetcode-gh#194 from thisiswhale/patch-1
Fixed 125-Valid-Palindrome.js
2 parents681f97a +1adba3f commit60c6a15

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

‎javascript/125-ValidPalindrome.js

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
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--
1+
varisPalindrome=function(s){
2+
letl=0,r=s.length-1;
3+
while(l<r){
4+
while(l<r&&!isAlphaNumeric(s[l])){
5+
l++;
6+
}
7+
while(r>l&&!isAlphaNumeric(s[r])){
8+
r--;
209
}
21-
returntrue
10+
if(s[l].toLowerCase()!==s[r].toLowerCase())returnfalse;
11+
l++;
12+
r--;
2213
}
14+
returntrue;
2315

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))
16+
functionisAlphaNumeric(c){
17+
return(
18+
('A'.charCodeAt(0)<=c.charCodeAt(0)&&c.charCodeAt(0)<='Z'.charCodeAt(0))||
19+
('a'.charCodeAt(0)<=c.charCodeAt(0)&&c.charCodeAt(0)<='z'.charCodeAt(0))||
20+
('0'.charCodeAt(0)<=c.charCodeAt(0)&&c.charCodeAt(0)<='9'.charCodeAt(0))
21+
)
2822
}
29-
30-
}
23+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp