当前位置:网站首页>125. Valid Palindrome
125. Valid Palindrome
2022-06-23 08:24:00 【ujn20161222】
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
Given a string s, return true if it is a palindrome, or false otherwise.
Example 1:
Input: s = "A man, a plan, a canal: Panama" Output: true Explanation: "amanaplanacanalpanama" is a palindrome.
Example 2:
Input: s = "race a car" Output: false Explanation: "raceacar" is not a palindrome.
Example 3:
Input: s = " " Output: true Explanation: s is an empty string "" after removing non-alphanumeric characters. Since an empty string reads the same forward and backward, it is a palindrome.
Constraints:
1 <= s.length <= 2 * 105sconsists only of printable ASCII characters.
Accepted
1,181,069
Submissions
2,868,121
class Solution:
def isPalindrome(self, s: str) -> bool:
beg,end=0,len(s)-1
while beg<=end:
while not s[beg].isalnum() and beg<end: beg+=1
while not s[end].isalnum() and beg<end: end-=1
if s[beg]==s[end] or s[beg].upper()==s[end].upper():
beg,end=beg+1,end-1
else:
return False
return True边栏推荐
- 4- draw ellipse, use timer
- Can portals be the next decentraland?
- 论文阅读【Quo Vadis, Action Recognition? A New Model and the Kinetics Dataset】
- You have a string of code, but do not support the lower version of go; Judge the go version number, you deserve it!
- 1-渐变、阴影和文本
- After easynvr video is enabled, no video file is generated. How to solve this problem?
- Code quality level 3 - readable code
- Set interface and set sub implementation classes
- 6-shining laser application of calayer
- XSS via host header
猜你喜欢

坑爹的“敬业福”:支付宝春晚红包技术大爆发

【云计算】GFS思想优势以及架构

Summary of communication mode and detailed explanation of I2C drive

Keng dad's "dedication blessing": red packet technology explosion in Alipay Spring Festival Gala

Why use growth neural gas network (GNG)?

为什么用生长型神经气体网络(GNG)?

Deep learning ----- different methods to realize vgg16

What are open source software, free software, copyleft and CC? Can't you tell them clearly?

Basic use of check boxes and implementation of select all and invert selection functions

点云库pcl从入门到精通 第十章
随机推荐
通信方式总结及I2C驱动详解
Set interface and set sub implementation classes
What are the PCB characteristics inspection items?
C # advanced learning -- virtual method
Integers and operators in go data types (3)
6-闪耀的激光-CALayer 的应用
The rtsp/onvif protocol video platform easynvr startup service reports an error "service not found". How to solve it?
Assembly (receive several n-digit decimal values (0~65535) from the keyboard and display their sum in different base numbers.)
When easynvr service is started, video cannot be played due to anti-virus software interception. How to deal with it?
Go 数据类型篇(三)之整型及运算符
坑爹的“敬业福”:支付宝春晚红包技术大爆发
Deep learning ----- different methods to implement lenet-5 model
Top 25 most popular articles on vivo Internet technology in 2021
Jetpack family - ViewModel
单编内核驱动模块
Android kotlin coroutines KTX extension
为什么用生长型神经气体网络(GNG)?
Set接口和Set子实现类
USB peripheral driver - debug
Object.defineProperty() 和 数据代理