Seawolf 发表于 2020-8-4 08:43:34

Leetcode 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.

Example 1:
Input: "aba"
Output: True
Example 2:
Input: "abca"
Output: True
Explanation: You could delete the character 'c'.
Note:
The string will only contain lowercase characters a-z. The maximum length of the string is 50000.

class Solution:
    def validPalindrome(self, s: str) -> bool:
      start = 0
      end = len(s) - 1
      
      while start <= end:
            if s != s:
                first = s
                second = s
                return first == first[::-1] or second == second[::-1]
            start += 1
            end -= 1
            
      return True
页: [1]
查看完整版本: Leetcode 680. Valid Palindrome II