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

Commit78e2060

Browse files
authored
Merge pull requestneetcode-gh#494 from neetcode-gh/revert-145-patch-4
Revert "Update 125-Valid-Palindrome.py"
2 parentsb78ea5a +857360f commit78e2060

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

‎125-Valid-Palindrome.py‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
classSolution:
22
defisPalindrome(self,s:str)->bool:
3-
l=0
4-
r=len(s)-1
5-
whilel<r:
6-
ifs[l].lower()==s[r].lower():
7-
l+=1
8-
r-=1
9-
continue
10-
11-
elifnot (65<=ord(s[l])<=90or97<=ord(s[l])<=122or48<=ord(s[l])<=57):
12-
l+=1
13-
elifnot (65<=ord(s[r])<=90or97<=ord(s[r])<=122or48<=ord(s[r])<=57):
14-
r-=1
15-
else:
3+
l,r=0,len(s)-1
4+
whilel<r:
5+
whilel<randnotself.alphanum(s[l]):
6+
l+=1
7+
whilel<randnotself.alphanum(s[r]):
8+
r-=1
9+
ifs[l].lower()!=s[r].lower():
1610
returnFalse
11+
l+=1
12+
r-=1
1713
returnTrue
14+
15+
# Could write own alpha-numeric function
16+
defalphanum(self,c):
17+
return (ord('A')<=ord(c)<=ord('Z')or
18+
ord('a')<=ord(c)<=ord('z')or
19+
ord('0')<=ord(c)<=ord('9'))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp