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

Commitc6f0615

Browse files
Merge pull requestneetcode-gh#145 from BHARAT0310/patch-4
Update 125-Valid-Palindrome.py
2 parents7fc7c8a +dd6151f commitc6f0615

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

‎125-Valid-Palindrome.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
classSolution:
22
defisPalindrome(self,s:str)->bool:
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():
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:
1016
returnFalse
11-
l+=1
12-
r-=1
1317
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