1216.Valid Palindrome III
Problem description:
Given a string s
and an integer k
, return true
if s
is a k
-palindrome.
A string is k
-palindrome if it can be transformed into a palindrome by removing at most k
characters from it.
Example 1:
1 | Input: s = "abcdeca", k = 2 |
Example 2:
1 | Input: s = "abbababa", k = 1 |
Constraints:
1 <= s.length <= 1000
s
consists of only lowercase English letters.1 <= k <= s.length
Solution:
bottom-up
Start from end of string
1 | class Solution: |
We actually only need i+1
th row and j-1
th column
1 | class Solution: |
time complexity: $O()$
space complexity: $O()$
reference:
related problem: