Number of Ways to Partition a String into a Palindromes - Go clear solution
func partition2(s string) int {
    dp := make([]int, len(s)+1); dp[0] = 1
    
    for i := 1; i <= len(s); i++ {
        for j := 0; j < i; j++ {
            if isPalindrome(s[j:i]) { dp[i] += dp[j] }
        }
    }
    return dp[len(s)]
}

func isPalindrome(s string) bool {
    for i:= 0; i < len(s)/2; i++ {
        if s[i] != s[len(s)-1-i] { return false }
    }
    return true
}
Comments (0)