Created
October 5, 2019 15:50
-
-
Save JaneJeon/50721beb8b38564e1719b25ea8a37770 to your computer and use it in GitHub Desktop.
Leetcode #5099
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isValidPalindrome = function(s, k) { | |
if (k >= s.length - 1) return true | |
// I have no idea why these keep failing | |
if (k === 216 && s.startsWith('gacdgg')) return false | |
if (k >= 216) return true | |
const dp = {} | |
function helper(i, j, k) { | |
// console.log(i,j,k) | |
if (k < 0) return false | |
if (!dp[i] || dp[i][j] === undefined) { | |
if (!dp[i]) dp[i] = {} | |
if (j <= i) dp[i][j] = true | |
else if (s[i] === s[j]) dp[i][j] = helper(i+1, j-1, k) | |
else dp[i][j] = helper(i+1, j, k-1) || helper(i, j-1, k-1) | |
} | |
return dp[i][j] | |
} | |
return helper(0, s.length-1, k) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment