当前位置:网站首页>Leetcode647. Palindrome substring
Leetcode647. Palindrome substring
2022-07-28 16:53:00 【be faithful to one 's husband unto death】
#include <string>
#include <iostream>
class Solution {
public:
int countSubstrings(std::string s)
{
int ret = 0;
if (s.empty() || s.length() <= 0)
{
return ret;
}
for (int i = 0; i < s.length(); i++)
{
for (int j = i + 1; j < s.length(); j++)
{
if (strIsPalindrome(s.substr(i, j - i + 1)))
{
ret++;
}
}
}
return ret + s.length();
}
// Determine whether the string is a palindrome
bool strIsPalindrome(const std::string& str)
{
int begin = 0;
int end = str.length() - 1;
while (begin < end)
{
if (str[begin] == str[end])
{
begin++;
end--;
}
else
{
return false;
}
}
return true;
}
};
int main()
{
Solution solution;
std::cout << solution.countSubstrings("abc") << std::endl;
std::cout << solution.countSubstrings("aaa") << std::endl;
return 0;
}边栏推荐
- Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
- Microsoft question 100 - do it every day - question 16
- Asp.net large file block upload breakpoint resume demo
- 小程序:scroll-view默认滑倒最下面
- Ansa secondary development - Introduction to interface development tools
- Configure HyperMesh secondary development environment on vs Code
- 有趣的 Kotlin 0x0A:Fun with composition
- Microsoft question 100 - do it every day - question 11
- Simple addition, deletion, modification and query of commodity information
- nowcode-学会删除链表中重复元素两题(详解)
猜你喜欢

Kubeedge releases white paper on cloud native edge computing threat model and security protection technology

【深度学习】:《PyTorch入门到项目实战》第九天:Dropout实现(含源码)

栈的介绍与实现(详解)

USB产品(FX3、CCG3PA)的调试方法

ANSA二次开发 - Visual Studio Code上搭建ANSA二次开发环境
![[pointer internal skill cultivation] character pointer + pointer array + array pointer + pointer parameter (I)](/img/e8/2044cae63fe2145ce6294cb1fdfaa0.png)
[pointer internal skill cultivation] character pointer + pointer array + array pointer + pointer parameter (I)

【深度学习】:《PyTorch入门到项目实战》第八天:权重衰退(含源码)

Configure HyperMesh secondary development environment on vs Code

Interesting kotlin 0x08:what am I

LeetCode-学会对无序链表进行插入排序(详解)
随机推荐
Analysis of echo service model in the first six chapters of unp
Sort 3-select sort and merge sort (recursive implementation + non recursive implementation)
“蔚来杯“2022牛客暑期多校训练营3 H.Hacker SAM+线段树/DP/分治(不带修查区间最大子段和)
排序1-插入排序与希尔排序
“蔚来杯“2022牛客暑期多校训练营3 J.Journey 0-1最短路
Text filtering skills
nowcode-学会删除链表中重复元素两题(详解)
ANSA二次开发 - Visual Studio Code上搭建ANSA二次开发环境
Best Cow Fences 题解
“蔚来杯“2022牛客暑期多校训练营3 A.Ancestor LCA+暴力计数
Each account corresponds to all passwords, and then each password corresponds to all accounts. How to write the brute force cracking code
局域网无法访问apache服务器
关于 CMS 垃圾回收器,你真的懂了吗?
【深度学习】:《PyTorch入门到项目实战》第八天:权重衰退(含源码)
Understanding of asmlinkage
智慧园区是未来发展的趋势吗?
Early in the morning, pay Bora SMS to say that you won the "prize"? Dealing with server mining virus - kthreaddi
QT designer for QT learning
阿里大哥教你如何正确认识关于标准IO缓冲区的问题
ANSYS secondary development - MFC interface calls ADPL file