Count Palindrome in String
来源:互联网 发布:蓝牙控制小车app源码 编辑:程序博客网 时间:2024/06/14 09:53
string 有多少palindrome substring。exp: 'aba' 返回4 , 'abba' 返回6
public class CountPalindrome {public int countPalindrome(String str){if(str == null || str.length() == 0) return 0;int count = 0;for(int i=0; i<str.length(); i++){//odd palindrome;count += find(str, i, i); // even palindromecount+= find(str, i, i+1);}return count;}public int find(String str, int start, int end){int count = 0;while(start>=0 && end<str.length()){if(str.charAt(start) == str.charAt(end)){count++;start--;end++;} else {break;}}return count;}public static void main(String[] args) {// TODO Auto-generated method stubCountPalindrome p = new CountPalindrome();System.out.println(p.countPalindrome("aba"));System.out.println(p.countPalindrome("abba"));}}
0 0
- Count Palindrome in String
- Count in String and Object
- Split string to palindrome
- 10739 - String to Palindrome
- UVA10739 - String to Palindrome
- String to Palindrome
- LeetCode[String]: Valid Palindrome
- String to Palindrome
- uva10739(String to Palindrome)
- String:125. Valid Palindrome
- LeetCode(五)387. First Unique Character in a String&409. Longest Palindrome
- hdu3336 Count the string
- hdu3336 Count the string
- HDU3336:Count the string
- hdu3336-Count the string
- Count the string + KMP
- hdu3336 Count the string
- Count the string (KMP)
- 统计学习方法——k近邻法
- 淘宝图片放大镜JavaScript效果
- 如何严格设置php中session过期时间
- 配置文件lighttpd.conf参数详细说明的链接和选译
- C#与C/C++的交互
- Count Palindrome in String
- 【Python】Python Assert 为何不尽如人意
- 浅谈C++普通指针和智能指针管理动态内存的陷阱
- Codeforces Round #378 (Div. 2)
- Nginx配置过程中问题记录
- work沉淀
- 安卓APK软件权限一览表
- c#创建带参数的线程
- dirent--文件以及文件夹相关操作(跨平台)