680. Valid Palindrome II 有效的回文2

Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.

Example 1:

Input: "aba"
Output: True

Example 2:

Input: "abca"
Output: True
Explanation: You could delete the character ‘c‘.

Note:

  1. The string will only contain lowercase characters a-z. The maximum length of the string is 50000.

给定一个非空字符串,您最多可以删除一个字符。判断你是否可以使它成为一个回文。

  1. class Solution:
  2. def validPalindrome(self, s):
  3. """
  4. :type s: str
  5. :rtype: bool
  6. """
  7. l = 0;
  8. r = len(s) - 1
  9. while l < r:
  10. if s[l] != s[r]:
  11. s1,s2 = s[l:r],s[l+1:r+1]
  12. return (s1 == s1[::-1]) or (s2 == s2[::-1])
  13. l +=1
  14. r -=1
  15. return True

来自为知笔记(Wiz)

时间: 2024-10-10 01:05:31

680. Valid Palindrome II 有效的回文2的相关文章

680. Valid Palindrome II【easy】

680. Valid Palindrome II[easy] Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. Example 1: Input: "aba" Output: True Example 2: Input: "abca" Output: True Explanation: You co

【Leetcode_easy】680. Valid Palindrome II

problem 680. Valid Palindrome II 参考 1. Leetcode_easy_680. Valid Palindrome II; 完 原文地址:https://www.cnblogs.com/happyamyhope/p/11091358.html

[leetcode]680. Valid Palindrome II有效回文II(可至多删一原字符)

Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. Example 1: Input: "aba" Output: True Example 2: Input: "abca" Output: True Explanation: You could delete the character 'c'. 思

【LeetCode】- Valid Palindrome(正确的回文)

[ 问题: ] Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. 直译:给你一个字符串, 判定它是否是回文(只统计字母.数字,其他字符请忽略). For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" i

680. Valid Palindrome II

Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. Input: "aba" Output: True Input: "abca" Output: True Explanation: You could delete the character 'c'. 判断字符串是不是回文,最多可以删除字符串的一个

680. Valid Palindrome II【Easy】【双指针-可以删除一个字符,判断是否能构成回文字符串】

Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. Example 1: Input: "aba" Output: True Example 2: Input: "abca" Output: True Explanation: You could delete the character 'c'. N

680. Valid Palindrome II - Easy

Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. Example 1: Input: "aba" Output: True Example 2: Input: "abca" Output: True Explanation: You could delete the character 'c'. N

131. 132. Palindrome Partitioning *HARD* -- 分割回文字符串

131. Palindrome Partitioning Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = "aab",Return [ ["aa","b"], ["

PE 4 Largest palindrome product(最大回文)

题目 A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. https://projecteuler.net/problem=1 分析 题