当前位置:网站首页>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;
}边栏推荐
- CRC16 data verification supports modelbus and XMODEM verification modes (C language)
- 在vs code上配置Hypermesh二次开发环境
- Ansa secondary development - build ansa secondary development environment on Visual Studio code
- Simple addition, deletion, modification and query of commodity information
- MySQL 5.7 and sqlyogv12 installation and use cracking and common commands
- Microsoft question 100 - do it every day - question 16
- 阿里云-武林头条-建站小能手争霸赛
- [pointer internal skill cultivation] character pointer + pointer array + array pointer + pointer parameter (I)
- Applet: get element node information
- Debugging methods of USB products (fx3, ccg3pa)
猜你喜欢

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

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

Interesting kotlin 0x07:composition

排序2-冒泡排序与快速排序(递归加非递归讲解)

Interesting kotlin 0x06:list minus list

Wake up after being repeatedly upset by MQ! Hate code out this MQ manual to help the journey of autumn recruitment

Do you really understand CMS garbage collector?

Leetcode learn to insert and sort unordered linked lists (detailed explanation)

Ansa secondary development - two methods of drawing the middle surface

【深度学习】:《PyTorch入门到项目实战》第八天:权重衰退(含源码)
随机推荐
First day of QT study
USB产品(FX3、CCG3PA)的调试方法
排序2-冒泡排序与快速排序(递归加非递归讲解)
Leetcode learn complex questions with random pointer linked lists (detailed explanation)
每一个账号对应所有密码,再每一个密码对应所有账号暴力破解代码怎么写?...
记录开发问题
leetcode647. 回文子串
Introduction and implementation of stack (detailed explanation)
获取时间戳的三种方法的效率比较
排序3-选择排序与归并排序(递归实现+非递归实现)
“蔚来杯“2022牛客暑期多校训练营3 J.Journey 0-1最短路
egg(十九):使用egg-redis性能优化,缓存数据提升响应效率
Do you really understand CMS garbage collector?
Quickly master kotlin set functions
Interesting kotlin 0x08:what am I
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
Interesting kotlin 0x09:extensions are resolved statically
PHP calculate coordinate distance
Detailed record of steps to configure web server (many references)
我该如何理解工艺