当前位置:网站首页>Verification palindrome string II of leetcode simple question
Verification palindrome string II of leetcode simple question
2022-07-26 19:05:00 【·Starry Sea】
subject
Given a non empty string s, Delete at most one character . Determine whether it can be a palindrome string .
Example 1:
Input : s = “aba”
Output : true
Example 2:
Input : s = “abca”
Output : true
explain : You can delete c character .
Example 3:
Input : s = “abc”
Output : false
Tips :
1 <= s.length <= 10^5
s It's made up of lowercase letters
source : Power button (LeetCode)
Their thinking
Whether it is palindrome is an old question , The common method can be traversal or stack , Here we use traversal . For the case that the string cannot be palindrome, we only need to check two cases , That is, the first half and the second half .
class Solution:
def validPalindrome(self, s: str) -> bool:
def Palindrome(x):
for i in range(len(x)//2):
if x[i]!=x[-i-1]:
return i
return None
temp=Palindrome(s)
if temp==None:
return True
else:
s1=s[0:temp]+s[temp+1:]
s2=s[0:len(s)-1-temp]+s[len(s)-temp:]
return False if Palindrome(s1)!=None and Palindrome(s2)!=None else True

边栏推荐
- Agenda express | list of sub forum agenda on July 27
- Offer set (1)
- CTO will teach you: how to take over his project when a technician suddenly leaves
- 此章节用于补充3
- 实用工具网站推荐
- The first ABAP ALV reporter construction process
- Use notes of Lichuang EDA
- [soft exam] soft exam tutorial + real questions over the years
- [add conditional behavior in kotlin]
- FTP协议
猜你喜欢

NFT digital collection system development: sold out when online, and netizens "spike" Digital Collections

5款WPS Office最佳海外替代品

Neural network learning (2) introduction 2

多线程学习笔记-1.CAS
![[soft exam] soft exam tutorial + real questions over the years](/img/91/72cdea3eb3f61315595330d2c9016d.png)
[soft exam] soft exam tutorial + real questions over the years

CTO will teach you: how to take over his project when a technician suddenly leaves

支持代理直连Oracle数据库,JumpServer堡垒机v2.24.0发布

JS uses readLine to realize terminal input data

SMMU carding

分布式事务-seata
随机推荐
The class jointly built by famous oarsmen is new, and Professor qiuxipeng of Fudan University broadcast it live on Tuesday!
工赋开发者社区 | 定了!就在7月30日!
2022G1工业锅炉司炉上岗证题库及模拟考试
Neural network learning (2) introduction 2
CTO will teach you: how to take over his project when a technician suddenly leaves
Redis学习笔记-2.客户端的使用
多线程学习笔记-1.CAS
Brand new! Uncover the promotion route of Ali P5 Engineer ~p8 architect
MySQL学习笔记-2.如何提高sql语句的查询性能
Sudden! Arm stops cooperating with Huawei! How big is the impact on Huawei?
基础模块及算例#pytorch学习
.Net CLR GC 动态加载短暂堆阈值的计算及阈值超量的计算
模型定义#pytorch学习
Agenda express | list of sub forum agenda on July 27
Complete MySQL database commands
Simulated 100 questions and simulated examination of refrigeration and air conditioning equipment operation examination in 2022
2022茶艺师(中级)考试题模拟考试题库及答案
What should we do after the PMP Exam is postponed on July 30?
This section is used to supplement 3
Development of NFT digital collection system: Shanxi first released digital collections of ancient buildings on "China Tourism Day"