摘要: 题目链接 647. 回文子串 思路 使用中心扩散法解决,在 【双指针】LeetCode 5. 最长回文子串 的代码上稍作修改即可。 代码 class Solution { public int countSubstrings(String s) { int result = 0; for(int i 阅读全文
posted @ 2023-01-27 21:47 Frodo1124 阅读(32) 评论(0) 推荐(0) 编辑
摘要: 题目链接 5. 最长回文子串 思路1:中心扩散法 遍历字符串 s,对于每个字符都以它为中心向两边扩散,测得最长回文子串。 注意:在扩散的过程中要分回文串长度奇偶进行扩散,因为长度为偶数的回文串中心是两个字母 时间复杂度:$O(n^2)$ 空间复杂度:$O(1)$ 代码1 class Solution 阅读全文
posted @ 2023-01-27 21:30 Frodo1124 阅读(56) 评论(0) 推荐(0) 编辑
摘要: 题目链接 680. 验证回文串 II 思路 题目允许删除一个字符,那么当我们判断到一对字符不相等时,可以分别判断区间 $[left + 1, right]$ 和区间 $[left, right - 1]$ 是否能构成回文串,只要有一个能构成回文串,则合法。 代码 class Solution { p 阅读全文
posted @ 2023-01-27 19:13 Frodo1124 阅读(24) 评论(0) 推荐(0) 编辑
摘要: 题目链接 125. 验证回文串 思路 简单双指针应用 代码 class Solution { public boolean isPalindrome(String s) { StringBuffer sgood = new StringBuffer(); int length = s.length( 阅读全文
posted @ 2023-01-27 18:49 Frodo1124 阅读(29) 评论(0) 推荐(0) 编辑