当前位置:网站首页>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;
}边栏推荐
- PHP calculate coordinate distance
- Redis source code optimization -- binding core
- ANSA二次开发 - Visual Studio Code上搭建ANSA二次开发环境
- Microsoft: edge browser has built-in disk cache compression technology, which can save space and not reduce system performance
- 阿里大哥教你如何正确认识关于标准IO缓冲区的问题
- ABAQUS GUI interface solves the problem of Chinese garbled code (plug-in Chinese garbled code is also applicable)
- Leetcode learn complex questions with random pointer linked lists (detailed explanation)
- Interesting kotlin 0x06:list minus list
- LeetCode-学会对无序链表进行插入排序(详解)
- Learn ABAQUS script programming script in an hour
猜你喜欢

ANSA二次开发 - Visual Studio Code上搭建ANSA二次开发环境

LeetCode-学会复杂带随机指针链表的题(详解)

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

大学生参加六星教育PHP培训,找到了薪水远超同龄人的工作

Using pyqt to design gui in ABAQUS

Learn to use MySQL explain to execute the plan, and SQL performance tuning is no longer difficult

Ansa secondary development - build ansa secondary development environment on Visual Studio code

Nowcode- learn to delete duplicate elements in the linked list (detailed explanation)

FX3开发板 及 原理图

Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
随机推荐
Applet: get element node information
LeetCode每日一练 —— 160. 相交链表
微软100题-天天做-第11题
WSL+Valgrind+Clion
每一个账号对应所有密码,再每一个密码对应所有账号暴力破解代码怎么写?...
leetcode9. 回文数
QT designer for QT learning
IM即时通讯开发优化提升连接成功率、速度等
Some suggestions on Oracle SQL tuning
队列的介绍与实现(详解)
ANSYS secondary development - MFC interface calls ADPL file
Sort 2 bubble sort and quick sort (recursive and non recursive explanation)
Solve the width overflow of rich text pictures such as uniapp
egg(十九):使用egg-redis性能优化,缓存数据提升响应效率
“蔚来杯“2022牛客暑期多校训练营3 H.Hacker SAM+线段树/DP/分治(不带修查区间最大子段和)
【指针内功修炼】字符指针 + 指针数组 + 数组指针 + 指针参数(一)
Design direction of daily development plan
信号屏蔽与处理
Ansa secondary development - two methods of drawing the middle surface
Interesting kotlin 0x08:what am I