当前位置 : 主页 > 手机开发 > harmonyos >

leetcode-5-Longest Palindromic Substring

来源:互联网 收集:自由互联 发布时间:2023-08-26
I am so stupid!!! Spent long time on that and cannot fix the bugs in short time. It has two solutions: the first is treat each element as the center, then expand base on the center and check the validation. The second is use dp, which equat


I am so stupid!!! Spent long time on that and cannot fix the bugs in short time.

It has two solutions: the first is treat each element as the center, then expand base on the center and check the validation. The second is use dp, which equation is dp[i][j] = s[i] == s[j] && dp[i + 1][j - 1]; which means whether the string from i to j is match or not. However, both of them spend lots of time to debug.

Which the first one blocked me because I miss a case when expanding, which is if the left and right is incorrect at first time, we should not return its minus value.

The second is I swap i and j when calculate length.


上一篇:POJ1852(Ant)
下一篇:没有了
网友评论