647. Palindromic Substrings
Given a string, your task is to count how many palindromic substrings in this string.
The substrings with different start indexes or end indexes are counted as different substrings even they consist of same characters.
Example 1:
Input: "abc"
Output: 3
Explanation: Three palindromic strings: "a", "b", "c".
Example 2:
Input: "aaa"
Output: 6
Explanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa". 回文子串的个数 java:
class Solution {
private int cnt = 0 ;
public int countSubstrings(String s) {
for(int i = 0 ; i < s.length() ; i++){
extendSubstrings(s,i,i) ;
extendSubstrings(s,i,i+1) ;
}
return cnt ;
}
private void extendSubstrings(String s , int left , int right){
while(left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)){
left-- ;
right++ ;
cnt++ ;
}
}
}
647. Palindromic Substrings的更多相关文章
- 【LeetCode】647. Palindromic Substrings 解题报告(Python)
[LeetCode]647. Palindromic Substrings 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/p ...
- [LeetCode] 647. Palindromic Substrings 回文子字符串
Given a string, your task is to count how many palindromic substrings in this string. The substrings ...
- Leetcode 647. Palindromic Substrings
Given a string, your task is to count how many palindromic substrings in this string. The substrings ...
- 647. Palindromic Substrings 互文的子字符串
[抄题]: Given a string, your task is to count how many palindromic substrings in this string. The subs ...
- 【Leetcode】647. Palindromic Substrings
Description Given a string, your task is to count how many palindromic substrings in this string. Th ...
- 【LeetCode】647. Palindromic Substrings 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:暴力循环 方法二:固定起点向后找 方法三:动 ...
- Manacher's Algorithm && 647. Palindromic Substrings 计算回文子串的算法
注:转载自:https://www.cnblogs.com/love-yh/p/7072161.html
- 647. Palindromic Substrings(马拉车算法)
问题 求一个字符串有多少个回文子串 Input: "abc" Output: 3 Input: "aaa" Output: 6 思路和代码(1)--朴素做法 用 ...
- LeetCode 647. Palindromic Substrings的三种解法
转载地址 https://www.cnblogs.com/AlvinZH/p/8527668.html#_label5 题目详情 给定一个字符串,你的任务是计算这个字符串中有多少个回文子串. 具有不同 ...
随机推荐
- js知识巩固
1.数组操作中使用splice和slice进行删除数组的区别! splice会对原数组进行操作,返回的是被删除元素组成的数组,原数组会被进行改变即变成删除后的数组,用于删除列表中的元素,arr.spl ...
- BCG界面库
之前用过BCG界面库中的表格控件,深感其强大,现在再来用一下其它的. 一. 关于BCGControlBar. BCGControlBar是一个基于MFC的扩展库,您可以通过完全的用户化操作构成一些 ...
- 关于nginx服务器上传限制
nginx的上传参数问题,需要特别注意client_max_body_size这个参数,否则会中断在nginx的请求中,在php中无法log到访问的.修改了php.ini文件如下:参数 设置 说明fi ...
- windows下java环境变量的配置 javac不是内部或外部命令的问题
安装配置JAVA JDK 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html . 下载你电脑对应的JDK,下 ...
- PHP一维数组转二维数组正则表达式
2017年11月20日17:17:08 array(1 => '哈哈') 变成 array('id' => 1, 'name' => '哈哈') 查找目标: (\d)\s=&g ...
- winform生成条形码和二维码(ZXing.Net)
首先在项目添加ZXing.Net. 工具-->Nuget包管理器-->Nuget程序包 在所搜栏输入 ZXing.Net 如下图: 添加完成后会看见: 效果图: 所有代码: /// &l ...
- windows被入侵检测
1.net user 查看当前有哪些用户 2.net localgroup administrators 查询administrators最高权限组有哪些用户 3.net user administr ...
- Codeforces 1091E New Year and the Acquaintance Estimation [图论]
洛谷 Codeforces 思路 有一个定理:Erdős–Gallai定理. 然后观察样例,可以猜到答案必定是奇偶性相同的一段区间,那么二分左右端点即可. 定理和这个猜测暂时都懒得学/证,留坑. #i ...
- iOS UIDatePicker设置为中文的方法
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 20, 200, 30)]; datePick ...
- FTP判断ftp上是否有文件目录,没有就创建的具体案例
/// <summary> /// 判断ftp上是否有指定的文件目录,没有创建 /// </summary> /// <param name="ftpPath& ...