当前位置:网站首页>Leetcode9. Palindromes
Leetcode9. Palindromes
2022-07-28 16:53:00 【be faithful to one 's husband unto death】
#include <iostream>
#include <string>
#define _DEBUG
class Solution {
public:
bool isPalindrome(int x)
{
std::string strX = int2Str(x);
return strIsPalindrome(strX);
}
// Integer to character to
std::string int2Str(int x)
{
return std::to_string(x);
}
// 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_leetcode9()
{
Solution solution;
#ifdef DEBUG
// int2Str The interface test
std::cout << solution.int2Str(123) << std::endl;
std::cout << solution.int2Str(-123) << std::endl;
// strIsPalindrome The interface test
std::cout << solution.strIsPalindrome("12321") << std::endl;
std::cout << solution.strIsPalindrome("-123") << std::endl;
#endif // DEBUG
std::cout << solution.isPalindrome(12321) << std::endl;
std::cout << solution.isPalindrome(-123) << std::endl;
return false;
}边栏推荐
- Introduction and implementation of stack (detailed explanation)
- Sort 4-heap sort and massive TOPK problem
- Simple addition, deletion, modification and query of commodity information
- 【从零开始学习SLAM】将坐标系变换关系发布到 topic tf
- Interesting kotlin 0x09:extensions are resolved statically
- Configure HyperMesh secondary development environment on vs Code
- Wake up after being repeatedly upset by MQ! Hate code out this MQ manual to help the journey of autumn recruitment
- 有趣的 Kotlin 0x09:Extensions are resolved statically
- Use js direct OSS to store files in Alibaba cloud and solve the limitation of large file upload server
- 队列的介绍与实现(详解)
猜你喜欢

【深度学习】:《PyTorch入门到项目实战》第四天:从0到1实现logistic回归(附源码)

IM即时通讯开发优化提升连接成功率、速度等
![[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入门到项目实战》第五天:从0到1实现Softmax回归(含源码)

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

Cluster construction and use of redis5

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

Sort 2 bubble sort and quick sort (recursive and non recursive explanation)

排序5-计数排序

Introduction and implementation of queue (detailed explanation)
随机推荐
College students participated in six Star Education PHP training and found jobs with salaries far higher than those of their peers
About mit6.828_ HW9_ Some problems of barriers xv6 homework9
Design direction of daily development plan
LeetCode每日一练 —— 剑指Offer 56 数组中数字出现的次数
【深度学习】:《PyTorch入门到项目实战》第七天之模型评估和选择(上):欠拟合和过拟合(含源码)
关于 CMS 垃圾回收器,你真的懂了吗?
Redis系列4:高可用之Sentinel(哨兵模式)
Several methods of HyperMesh running script files
微软100题-天天做-第16题
FX3开发板 及 原理图
Ruoyi集成flyway后启动报错的解决方法
HyperMesh auto save (enhanced) plug-in instructions
Multiple commands produce ‘.../xxx.app/Assets.car‘问题
小程序:scroll-view默认滑倒最下面
Im im development optimization improves connection success rate, speed, etc
在vs code上配置Hypermesh二次开发环境
HM secondary development - data names and its use
获取时间戳的三种方法的效率比较
Signal shielding and processing
关于MIT6.828_HW9_barriers xv6 homework9的一些问题