当前位置:网站首页>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;
}边栏推荐
- 有趣的 Kotlin 0x06:List minus list
- Ruoyi集成flyway后启动报错的解决方法
- 获取时间戳的三种方法的效率比较
- Microsoft question 100 - do it every day - question 11
- leetcode647. 回文子串
- 结构化设计的概要与原理--模块化
- Using pyqt to design gui in ABAQUS
- Li Hongyi, machine learning 5. Tips for neural network design
- Interesting kotlin 0x07:composition
- leetcode9. 回文数
猜你喜欢

Leetcode learn complex questions with random pointer linked lists (detailed explanation)

IM即时通讯软件开发网络请求成功率的优化

TCP handshake, waving, time wait connection reset and other records

nowcode-学会删除链表中重复元素两题(详解)

egg(十九):使用egg-redis性能优化,缓存数据提升响应效率

Text filtering skills

【深度学习】:《PyTorch入门到项目实战》第七天之模型评估和选择(上):欠拟合和过拟合(含源码)

Microsoft: edge browser has built-in disk cache compression technology, which can save space and not reduce system performance

队列的介绍与实现(详解)

LeetCode每日一练 —— 剑指Offer 56 数组中数字出现的次数
随机推荐
[pointer internal skill cultivation] character pointer + pointer array + array pointer + pointer parameter (I)
Ruoyi集成flyway后启动报错的解决方法
LeetCode每日一练 —— 剑指Offer 56 数组中数字出现的次数
Some suggestions on optimizing HyperMesh script performance
【指针内功修炼】字符指针 + 指针数组 + 数组指针 + 指针参数(一)
IM即时通讯软件开发网络请求成功率的优化
Best Cow Fences 题解
ANSYS secondary development - MFC interface calls ADPL file
LeetCode-学会复杂带随机指针链表的题(详解)
Quickly master kotlin set functions
Introduction and implementation of stack (detailed explanation)
Debugging methods of USB products (fx3, ccg3pa)
mysql cdc 如果binlog日志文件不全,全量阶段能读到所有数据吗
Design direction of daily development plan
Im im development optimization improves connection success rate, speed, etc
Splash (渲染JS服务)介绍安装
ANSA二次开发 - Visual Studio Code上搭建ANSA二次开发环境
About mit6.828_ HW9_ Some problems of barriers xv6 homework9
Do you really understand CMS garbage collector?
USB产品(FX3、CCG3PA)的调试方法