LeetCode 647. 回文子串(Palindromic Substrings)
647. 回文子串
647. Palindromic Substrings
题目描述
给定一个字符串,你的任务是计算这个字符串中有多少个回文子串。
具有不同开始位置或结束位置的子串,即使是由相同的字符组成,也会被计为是不同的子串。
LeetCode647. Palindromic Substrings中等
示例 1:
输出: 3
解释: 3 个回文子串: "a", "b", "c"。
示例 2:
输出: 6
说明: 6 个回文子串: "a", "a", "a", "aa", "aa", "aaa"。
注意:
- 输入的字符串长度不会超过 1000。
 
Java 实现
class Solution {
    public int countSubstrings(String s) {
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            count += extractPalindrome(s, i, i);
            count += extractPalindrome(s, i, i + 1);
        }
        return count;
    }
    public int extractPalindrome(String s, int left, int right) {
        int count = 0;
        while (left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)) {
            count++;
            left--;
            right++;
        }
        return count;
    }
}

相似题目
参考资料
- https://leetcode-cn.com/problems/palindromic-substrings/
 - https://leetcode.com/problems/palindromic-substrings/
 
LeetCode 647. 回文子串(Palindromic Substrings)的更多相关文章
- Java实现 LeetCode 647 回文子串(暴力)
		
647. 回文子串 给定一个字符串,你的任务是计算这个字符串中有多少个回文子串. 具有不同开始位置或结束位置的子串,即使是由相同的字符组成,也会被计为是不同的子串. 示例 1: 输入: "a ...
 - [Swift]LeetCode647. 回文子串 | Palindromic Substrings
		
Given a string, your task is to count how many palindromic substrings in this string. The substrings ...
 - [LeetCode] 647. 回文子串 ☆☆☆(最长子串、动态规划、中心扩展算法)
		
描述 给定一个字符串,你的任务是计算这个字符串中有多少个回文子串. 具有不同开始位置或结束位置的子串,即使是由相同的字符组成,也会被计为是不同的子串. 示例 1: 输入: "abc" ...
 - [LeetCode]647. 回文子串(DP)
		
###题目 给定一个字符串,你的任务是计算这个字符串中有多少个回文子串. 具有不同开始位置或结束位置的子串,即使是由相同的字符组成,也会被计为是不同的子串. 示例 1: 输入: "abc&q ...
 - Leetcode 647.回文子串
		
回文子串 给定一个字符串,你的任务是计算这个字符串中有多少个回文子串. 具有不同开始位置或结束位置的子串,即使是由相同的字符组成,也会被计为是不同的子串. 示例 1: 输入: "abc&qu ...
 - Leetcode之动态规划(DP)专题-647. 回文子串(Palindromic Substrings)
		
Leetcode之动态规划(DP)专题-647. 回文子串(Palindromic Substrings) 给定一个字符串,你的任务是计算这个字符串中有多少个回文子串. 具有不同开始位置或结束位置的子 ...
 - leetcode解析回文子串拆分
		
转载请注明来自souldak,微博:@evagle Given a string s, partition s such that every substring of the partition i ...
 - [LeetCode] 5. Longest Palindromic Substring 最长回文子串
		
Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...
 - 求最长回文子串 - leetcode 5. Longest Palindromic Substring
		
写在前面:忍不住吐槽几句今天上海的天气,次奥,鞋子里都能养鱼了...裤子也全湿了,衣服也全湿了,关键是这天气还打空调,只能瑟瑟发抖祈祷不要感冒了.... 前后切了一百零几道leetcode的题(sol ...
 
随机推荐
- django-带参数路由
			
路由urls.py from django.conf.urls import url from goods.views import IndexView, DetailView, ListView u ...
 - LeetCode 837. New 21 Game
			
原题链接在这里:https://leetcode.com/problems/new-21-game/ 题目: Alice plays the following game, loosely based ...
 - 10.31-11.1Test(未完)
			
10.31-11.1Test 题目 描述 做法 \(BSOJ5177\) 求在\(n\)个数里选\(K\)个的所有方案的异或和之和 按位讨论,组合数算 \(BSOJ5178\) 化简\(\displa ...
 - learning scala someElements
			
The Scala collections library provides specialised implementations for Sets of fewer than 5 values ( ...
 - git的搭建和使用
			
目录: 1.git与github介绍2.下载安装Git-20-64-bit.exe3.Git常用命令 git与github介绍 Git是什么 Git是一个开源的[分布式][版本控制系统],用于敏捷高效 ...
 - 关于System.ArgumentNullException异常
			
什么是ArgumentNullException 当将 null 引用(Visual Basic 中为 Nothing)传递到不接受其作为有效参数的方法时引发的异常. 继承 Object Except ...
 - 文件搜索命令find
			
1.路径加文件名搜索(find): 查找的是etc目录下的以init为名字的文件. 加通配符后为模糊搜索,只要文件名中含有init即可. 查找etc目录下以init开头的七位文件名. 2.搜索时不区分 ...
 - Omnibus-ctl: What is it and what can it do for you?
			
转自:https://blog.chef.io/2015/05/26/omnibus-ctl-what-is-it-and-what-can-it-do-for-you/ Are you buildi ...
 - CSS行内元素
			
一.典型代表 span a ,strong em del, ins 二.特点: 在一行上显示 不能直接设置宽高 元素的宽和高就是内容撑开的宽高. <style type="text/c ...
 - TICK/TIGK运维栈安装运行 docker【中】
			
InfluxDB docker search influxdb docker pull influxdb docker run -d -p 8086:8086 -v /var/lib/influxdb ...