Re: 谁先投入谁先死# Joke - 肚皮舞运动
r*t
1 楼
Q: Find the number of substrings of a string that are palindromes.
Can it be solved by O(n)?
My idea is to build an array p[i,j]=1 if string(i,...j) is palindrome
otherwise p[i,j]=0. Then sum of p[i,j] is the total number. This is a DP
idea by O(n^2).
Better solution? Thanks.
Can it be solved by O(n)?
My idea is to build an array p[i,j]=1 if string(i,...j) is palindrome
otherwise p[i,j]=0. Then sum of p[i,j] is the total number. This is a DP
idea by O(n^2).
Better solution? Thanks.