当前位置:网站首页>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;
}
};边栏推荐
- DBMS in Oracle_ output. put_ Example of line usage
- 预训练语言模型,bert,RoFormer-Sim又称SimBERTv2
- 直播预告 | 12位一作华人学者开启 ICLR 2022
- Jenkins容器安装ruby-runtime插件失败报错解决
- Linked list 4- 21 merge two ordered linked lists
- postman学习
- JVM quick start
- I became a big enemy when I bought wanghong ice cream
- Does CDC 2.2.1 monitoring sqlserver not support monitoring multiple databases?
- What happened to this page when sqlserver was saving
猜你喜欢
![[win11] right click fix to modify the registry but not create a new one](/img/5c/1ce29da6f1325f9f6c84984ae0c2e5.png)
[win11] right click fix to modify the registry but not create a new one

阻碍华为5G手机的关键芯片取得突破,国产芯片已取得一成份额

Grafana 9 正式发布,更易用,更酷炫了!

"Half of Zhejiang's Venture Capital Circle" must be state-owned assets
Set of redis data structure

I became a big enemy when I bought wanghong ice cream

面试MySQL

Cookie encryption 3+rpc solution

如何持续突破性能表现? | DX研发模式

腾讯云国际版云服务器欠费说明
随机推荐
RSPS2022 Finalist | Dr. Yang Bai 简介
新人报道的笔记
2022年R2移动式压力容器充装试题模拟考试平台操作
wpa_supplicant的状态机迁移
A course for New Oriental transformation bilingual live broadcast to bring goods to the project manager
Exness sorted out three problems to be solved in Musk's acquisition of Twitter
2022年T电梯修理复训题库及答案
plsql变量赋值问题
【工具】pip和conda的相关使用
@Lucky user of "Qilu Duojiao", Shandong 5A scenic spot calls you to visit the park for free!
Array emulation stack
游戏NFT市场:OpenSea最易被切下的蛋糕
Sort---
Postman learning
【 outils】 utilisation de PIP et de conda
Babbitt | yuancosmos daily must read: it is said that Tencent has established XR department, and yuancosmos sector has risen again. Many securities companies have issued reports to pay attention to th
C sqlsugar, hisql, FreeSQL ORM framework omni-directional performance test comparison sqlserver
[win11] right click fix to modify the registry but not create a new one
2022 operation of simulated examination platform for examination question bank of welder (elementary) special operation certificate
【win11】注册表修改fix 右键没有新建