当前位置:网站首页>每日一题 -- 验证回文串
每日一题 -- 验证回文串
2022-06-11 21:36:00 【爱学代码的学生】
题目描述:

实现思路:
1. 首先我们要将字母统一化
2. 创建两个指针,一个从头部出发一个从尾部出发
3. 比较两个指针所指向的数据是否相同
代码如下:
bool isPalindrome(char * s){
char *ret= (char*)malloc(sizeof(char)*strlen(s));//不能对字符串直接进行修改,所以我们建立一个ret数组用来存储s中的值
int start = 0;
int end = strlen(s) - 1;
for (int i = 0; i <= end; i++) {//将s中的值拷贝在ret中,并且将字母都小写
ret[i] = s[i];
if (isalpha(ret[i])&&isupper(ret[i])) {
ret[i] += 32;
}
}
while (start < end) {
while (start < end && !isalpha(ret[start])&&!isdigit(ret[start])) //跳过除了字符和数字以外的字符
start++;
while (start < end && !isalpha(ret[end])&&!isdigit(ret[end]))
end--;
if (start < end&&ret[start] != ret[end])//进行比较
return false;
start++;
end--;
}
return true;
}边栏推荐
- Realize the same length of tablayout subscript and text, and change the selected font size
- UML系列文章(29)体系结构建模---模式和框架
- Parker plunger pump pv180r1k1t1nmmc
- 实验10 Bezier曲线生成-实验提高-交互式生成B样条曲线
- AC自动机
- Website online customer service system Gofly source code development log - 2 Develop command line applications
- JS performs non empty judgment on various data types of the returned data.
- 网络连接正常但百度网页打不开显示无法访问此网站解决方案
- Expérience 10 génération de courbes bezier - amélioration expérimentale - génération de courbes B - spline par point de contrôle
- RPA超自动化 | 农耕记携手云扩加速财务智能化运营
猜你喜欢

Leetcode-32- longest valid bracket

行而不辍,未来可期|云扩科技入选上海市专精特新企业

How to use RPA robot to start the first step of digital transformation of freight forwarding industry?

UML系列文章(29)体系结构建模---模式和框架

Codeforces Round #744 (Div. 3) 解题报告

EndnoteX9简介及基本教程使用说明

类和对象(2)

Iros 2021 | new idea of laser vision fusion? Lidar intensity diagram +vpr

JVM | runtime data area; Program counter (PC register);

JVM|虚拟机栈(局部变量表;操作数栈;动态链接;方法的绑定机制;方法的调用;方法返回地址)
随机推荐
Chain storage structure of linear table
Refresh and upgrade | innovation, starting from cloud store
The network connection is normal, but Baidu web page can not be opened and displayed. You can't access this website solution
Redis basic data type (hash)
bzoj3188 Upit
为什么需要微服务
Master of a famous school has been working hard for 5 years. AI has no paper. How can the tutor free range?
JVM | local method interface; Native Method Stack
RPA+低代码为何是加速财务数字化转型之利器?
Introduction à endnotex9 et instructions pour les tutoriels de base
Experiment 10 Bezier curve generation - experiment improvement - interactive generation of B-spline curve
如何使用事物码 SAT 查找某个 SAPGUI 屏幕字段对应的后台存储数据库表的名称
JVM|前言介绍
flutter系列之:flutter中常用的container layout详解
apache 本地多端口配置
JVM class loader; Parental delegation mechanism
Flutter series: detailed explanation of container layout commonly used in flutter
Codeforces Round #742 (Div. 2) F. One-Four Overload
Redis basic data type (Zset) ordered collection
RPA丨首席财务官如何找到数字化转型“超级入口”?