In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to verify palindromes in leetcode. It is very detailed and has certain reference value. Friends who are interested must finish reading it.
Given a non-empty string s, delete at most one character. Determine whether it can become a palindrome string.
Example 1:
Enter: "aba"
Output: True
Example 2:
Enter: "abca"
Output: True
Explanation: you can delete the c character.
Note:
The string contains only lowercase letters from amerz. The maximum length of a string is 50000.
Test venue:
Palindromes have the same properties as positive and negative order.
Solution:
Start the comparison from the beginning to the end, and if it is not equal, delete one end and continue down.
Class Solution: def validPalindrome (self S: str)-> bool: # cycle to distinguish''def help (s): if s = = s [::-1]: return True else: return False if help (s): return True length = len (s) for i in range (length): If help (s [: I] + s [iTun1:]): return True return False''# starts from both ends left = 0 right = len (s)-1 while left < right: if s [left]! = s [right]: return s [left: right] = = s [left: Right] [:-1] or s [left+1: right+1] = = s [left+1: right+1] [::-1] left+ = 1 right-= 1 return True are all the contents of the article "how to verify palindromes in leetcode" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.