当前位置:网站首页>Niuke.com: judge whether it is palindrome string
Niuke.com: judge whether it is palindrome string
2022-06-22 19:03:00 【lsgoose】

There are two ways to solve this problem
Catalog
1. Double pointer
We can go from two ends to the middle or from the middle to both sides , In a word, we use this symmetrical structure
The code is as follows :
class Solution {
public:
/**
* The class name in the code 、 Method name 、 The parameter name has been specified , Do not modify , Return the value specified by the method directly
*
* @param str string character string The string to be judged
* @return bool Boolean type
*/
bool judge(string str) {
// write code here
int left=0;
int right=str.length()-1;
while(left<right){
if(str[left]!=str[right]){
return false;
}
left++;
right--;
}
return true;
}
};2. Stack ( Flip )
If the idea of stack is to flip the string . Then use this string to check whether it is different from the original string .
The code is as follows :
class Solution {
public:
/**
* The class name in the code 、 Method name 、 The parameter name has been specified , Do not modify , Return the value specified by the method directly
*
* @param str string character string The string to be judged
* @return bool Boolean type
*/
bool judge(string str) {
// write code here
string tmp=str;
reverse(tmp.begin(), tmp.end());
if(tmp!=str){
return false;
}
return true;
}
};边栏推荐
- CONDA - basic configuration command summary
- 请问一下,CDC2.0在读取mysql的时候,应该是没有表锁了吧,刚刚报了一个错误,access d
- Conda——基础配置命令总结
- Concepts and solutions of redis' cache penetration, cache avalanche and cache breakdown problems
- List的同步类比较
- SystemVerilog(十二)-$unit声明空间
- Explain the startup process of opengauss multithreading architecture in detail
- Golang实现基于Redis的可靠延迟队列
- 数组实现循环链表
- How can I automatically make an appointment to make a new debt? Is it convenient and safe to make an appointment to make a new bond
猜你喜欢

Dynamically changing the style of label elements in a loop

What is the experience of writing a best seller

Redis中的布隆过滤器与布谷鸟过滤器,你了解多少?

游戏NFT市场:OpenSea最易被切下的蛋糕

写一本畅销书是怎样的一种体验

牛客网:合并区间
Golang实现基于Redis的可靠延迟队列

巴比特 | 元宇宙每日必读:传腾讯成立XR部门,元宇宙板块再次上涨,多家券商发报告关注虚拟人的投资机会...

Postman learning

I became a big enemy when I bought wanghong ice cream
随机推荐
Does CDC 2.2.1 monitoring sqlserver not support monitoring multiple databases?
零基础学编程/学逆向/过检测(frida实战)
在循环中动态改变标签元素的样式
When do project managers particularly want to escape from work?
Nuxt - Universal (SSR / SSG) / single page app (rendering mode)
自定义数据库连接池类: 要求:封闭一个Collection对象的集合类
Plan and change of continuous repair
Centeros install mangodb
请问一下,CDC2.0在读取mysql的时候,应该是没有表锁了吧,刚刚报了一个错误,access d
C sqlsugar, hisql, FreeSQL ORM framework omni-directional performance test comparison sqlserver
RobotFramework 安装教程
centerOS 安装mangodb
< JVM part I: memory and garbage collection part > 08 object instantiation and direct memory
新东方转型双语直播带货给项目管理人的一场课
2022焊工(初级)特种作业证考试题库模拟考试平台操作
腾讯云国际版云服务器欠费说明
Unity中通过射线躲避障碍物寻路的一些初步探索
Cookie encryption 3+rpc solution
[tools] related use of PIP and CONDA
In May, 2022, China's game manufacturers and applications went to sea, with top 30 revenue in EMEA region