当前位置:网站首页>每日一题 -- 验证回文串
每日一题 -- 验证回文串
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;
}边栏推荐
- 建造者模式
- Experiment 10 Bezier curve generation - experiment improvement - interactive generation of B-spline curve
- [v2.1] automatic update system based on motion step API (repair bug, increase completion display, support disconnection reconnection and data compensation)
- Parker plunger pump pv180r1k1t1nmmc
- The upcoming launch of the industry's first retail digital innovation white paper unlocks the secret of full link digital success
- 行而不辍,未来可期|云扩科技入选上海市专精特新企业
- Servlet get form data
- Educational Codeforces Round 114 (Rated for Div. 2) D
- 华为设备配置HoVPN
- Educational Codeforces Round 114 (Rated for Div. 2) D
猜你喜欢

如何查看win系统的安装日期

Codeforces Round #744 (Div. 3) 解题报告
![Game client performance (memory) [previous]](/img/b6/869b83e92efcdf95aa6bd5e8ff0d10.jpg)
Game client performance (memory) [previous]

LabVIEW controls Arduino to realize infrared ranging (advanced chapter-6)

Leetcode-110-balanced binary tree

如何利用RPA机器人开启货代行业数字化转型第一步?

关于斜率优化

flutter系列之:flutter中常用的container layout详解

The upcoming launch of the industry's first retail digital innovation white paper unlocks the secret of full link digital success

Leetcode-129- sum of numbers from root node to leaf node
随机推荐
Experiment 10 Bezier curve generation - experiment improvement - control point generation of B-spline curve
[v2.1] automatic update system based on motion step API (repair bug, increase completion display, support disconnection reconnection and data compensation)
联调这夜,我把同事打了...
行而不辍,未来可期|云扩科技入选上海市专精特新企业
LabVIEW控制Arduino实现红外测距(进阶篇—6)
Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
Some error reporting assemblies of cann code
如何使用事物码 SAT 查找某个 SAPGUI 屏幕字段对应的后台存储数据库表的名称试读版
八、BOM - 章节课后练习题及答案
JS performs non empty judgment on various data types of the returned data.
俩月没发过博客了,发一篇证明自己的账号还活着
flutter系列之:flutter中常用的container layout详解
EndnoteX9简介及基本教程使用说明
类和对象(2)
Redis basic data type (Zset) ordered collection
LeetCode-98-验证二叉搜索树
作为一名 ABAP 资深顾问,下一步可以选择哪一门 SAP 技术作为主攻方向?
A collection of commonly used open source data sets for face recognition
Apache local multi port configuration
Codeforces Round #742 (Div. 2) F. One-Four Overload