[LeetCode] 647. Palindromic Substrings
来源:互联网 发布:情侣头像 知乎 编辑:程序博客网 时间:2024/05/16 15:35
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 {public: int countSubstrings(string s) { const int n = s.size(); vector<vector<bool>> dp(n, vector<bool>(n, false)); int cnt = 0; for (int j = 0; j < n; j++) { dp[j][j] = true; cnt++; for (int i = 0; i < j; i++) { if (s[i] == s[j] && (i + 1 == j || dp[i + 1][j - 1])) { dp[i][j] = true; cnt++; } } } return cnt; }};
阅读全文
0 0
- [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:M-647. Palindromic Substrings
- LeetCode 647. Palindromic Substrings[Medium]
- Dynamic Programing -- Leetcode problem 647. Palindromic Substrings
- Leetcode 647.Palindromic Substrings(算法分析week15)
- LeetCode-Palindromic Substrings
- LeetCode:Palindromic Substrings
- 行为型-观察者模式(Observer)
- ActivityA 到 ActivityB 到 ActivityC 出现的问题
- Js中sort()方法的用法
- 返回顶部的三种方法
- 在eclipse中高亮显示其他相同的字符串
- [LeetCode] 647. Palindromic Substrings
- C#事件和委托
- react项目开发中路由的使用
- 利用phpExcel实现Excel数据的导入导出(全步骤详细解析)
- H264 sps pps 解析
- 小白成长记——Java基础之字符串类
- 软件测试中的基础小知识-后台
- 进程间通信
- DISM用于Win7部署的实验笔记