LeetCode:M-647. Palindromic Substrings
来源:互联网 发布:编写java 用什么软件 编辑:程序博客网 时间:2024/06/05 10:14
LeetCode链接
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: 3Explanation: Three palindromic strings: "a", "b", "c".
Example 2:
Input: "aaa"Output: 6Explanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa".
Note:
- The input string length won't exceed 1000.
class Solution { int cnt=0; public int countSubstrings(String s) { if(s==null || s.length()==0) return 0; for(int i=0; i<s.length(); i++){ extendPalindrome(s, i, i);//自己也算一个,奇数个数的回文扩展 extendPalindrome(s, i, i+1);//偶数个数的回文扩展 } return cnt; } void extendPalindrome(String str, int s, int e){ while(s>=0 && e<str.length() && str.charAt(s)==str.charAt(e)){ s--; e++; cnt++; } }}
阅读全文
0 0
- LeetCode:M-647. Palindromic Substrings
- [leetcode]647. Palindromic Substrings
- leetcode 647. Palindromic Substrings
- [LeetCode]647. Palindromic Substrings
- leetcode 647. Palindromic Substrings
- [LeetCode] 647. Palindromic Substrings
- 【LeetCode】647. Palindromic Substrings
- Leetcode 647. Palindromic Substrings
- LeetCode:647. Palindromic Substrings
- #leetcode#647. Palindromic Substrings
- [LeetCode] 647. Palindromic Substrings
- leetcode 647. Palindromic Substrings
- [LeetCode]647. Palindromic Substrings
- LeetCode 647. Palindromic Substrings[Medium]
- (M)Dynamic Programming:647. Palindromic Substrings
- Dynamic Programing -- Leetcode problem 647. Palindromic Substrings
- Leetcode 647.Palindromic Substrings(算法分析week15)
- LeetCode-Palindromic Substrings
- 手机版模板 {dede:field.position /} 的用法
- Android 选择文件、拍照等需要注意的问题
- Array.prototype.filter()+forEach()
- Python中统计函数的运行耗时
- 进入Ruby的世界——基础篇
- LeetCode:M-647. Palindromic Substrings
- 关于notifydatasetchange的一些理解
- 设计模式学习笔记1--单例模式
- 让js中的函数只有一次有效调用的三种常用方法
- XZ_HTML5之HTML5头部和元信息
- 关于BeanUtils.copyProperties的用法和优缺点
- java基础类的学习---Character类
- Qt两种定时器案例
- context应用启动时创建流程