# Valid Palindrome III

Given a string s and an integer k, find out if the given string is a K-Palindrome or not.

A string is K-Palindrome if it can be transformed into a palindrome by removing at most k characters from it.

Example 1:

Input: s = "abcdeca", k = 2
Output: true
Explanation: Remove 'b' and 'e' characters.

Constraints:

• 1 <= s.length <= 1000
• s has only lowercase English letters.
• 1 <= k <= s.length

class Solution {
public boolean isValidPalindrome(String s, int k) {
if(s == null || s.length() == 0) {
return false;
}
int n = s.length();
int[][] dp = new int[n][n];
for(int i = 0; i < n; i++) {
dp[i][i] = 1;
}
char[] ss = s.toCharArray();
for(int i = n - 1; i >= 0; i--) {
for(int j = i + 1; j < n; j++) {
if(ss[i] == ss[j]) {
if(i + 1 < n && j - 1 >= 0) {
dp[i][j] = dp[i + 1][j - 1] + 2;
}
} else {
// ss[i] != s[j];
if(i + 1 < n && j - 1 >= 0) {
dp[i][j] = Math.max(dp[i + 1][j], dp[i][j - 1]);
}
}
}
}
return dp[0][n - 1] >= n - k;
}
}

09-19 1517

03-24 50

01-01 433

10-09 447

04-02 28

08-14 458

04-03 475

01-30 847

10-03 508

11-05 74

07-26 80

07-12 68

07-18 46

11-05 105

08-14 3568

02-04 1128

10-18 238

09-28 52

02-01 373

09-23 50

04-14 59万+

03-13 15万+

03-04 14万+

03-08 2万+

04-25 6万+

03-10 13万+

03-10 18万+

03-12 11万+

03-13 11万+

03-18 9921

03-19 8万+

03-19 3万+

03-22 4万+

03-23 4万+

03-24 3万+

03-25 3万+

05-08 5万+

03-25 9万+

03-29 21万+

03-29 10万+

03-30 16万+

05-31 6318

05-31 1万+

04-02 1万+

04-02 5667

04-02 4万+

04-06 1万+

04-06 7万+

04-09 8万+

04-09 2万+

05-17 8575

04-11 3万+

04-15 6万+

04-18 4万+

04-20 4万+

04-24 3万+

05-01 6433

05-03 1万+

05-16 5万+

05-06 1万+

05-07 2748

05-07 1万+

05-08 4万+

05-10 3312

05-14 6529

05-16 3602

05-16 1万+

05-17 5085

05-30 383

05-20 1006

05-18 2259

05-18 8433

05-27 1452

05-18 3621

05-28 1292

05-19 1万+

05-19 1943

05-21 7607

#### 石锤！今年Python要过苦日子了？ 程序员：我疯了！

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客