【Easy】125. Valid Palindrome

125. Valid Palindrome [easy] (Python) 125. Valid Palindrome [easy] (Python)题目链接https://leetcode.com/problems/valid-palindrome/题目原文 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cas 阅读详情

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

For example,
"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome.


中心思想:

从两端开始数。由于无视大小写和其它符号,先把干净的小写字符串整理出来。
注意容易错的地方: alphanumeric是指字母和数字。还有,转换成全小写字符串tmp之后,无论是字符串长度还是提取char都在tmp上处理

class Solution {
public:
    bool isPalindrome(string s) {
<span style="white-space:pre">	</span> string tmp = "";
        for (int i = 0; i < n; i++){
            if ((s[i] >= 'a' && s[i] <= 'z') || s[i] >= '0' && s[i] <= '9' ){
                tmp += s[i];
            }
            else if (s[i] >= 'A' && s[i] <= 'Z'){
                tmp += (s[i] + 32);
            }
        }
        
        if (tmp.size() == 0 || tmp.size() == 1)
            return true;
        
        int left = 0;
        int right = tmp.size()-1;
        
        while (left < right){
            if (tmp[left] != tmp[right])
                return false;
            left++;
            right--;
        }
        
        return true;
    }
};


Easy 125题 Valid Palindrome Question: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a 阅读详情

相关推荐

从加权最小二乘(WLS)到IAA:手把手推导DOA估计中的迭代自适应核心公式

本文深入解析了从加权最小二乘(WLS)到迭代自适应算法(IAA)在DOA估计中的数学推导与应用。通过动态调整加权矩阵,IAA在低快拍数、相干源等复杂场景中展现出卓越性能,显著提升角度分辨率和检测概率。文章详细介绍了算法核心步骤、工程优化策略及前沿发展,为雷达探测和无线通信领域提供重要参考。

weixin_30847865的博客 297

[Leetcode 125, easy] Valid Palindrome

[Leetcode 125, easy] Valid Palindrome

算法的实践 445

合成孔径雷达(SAR)的常见工作模式

随着星载SAR技术研究的深入发展,单一的条带模式已经无法满足当今时代的需求,因此许多新的工作模式相继被提出。这些新模式在分辨率和测绘宽度等方面都有所提高,接下来将简要介绍几种常用的工作模式。

m0_51390495的博客 2321

Leetcode OJ 125 Valid Palindrome [Easy]

Leetcode OJ 125 Valid Palindrome 题目描述: Given a string, determine if it is a palindrome,considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama"

大吱的博客 344

实践指南——【SPSS操作解析】线性混合效应模型在重复测量数据中的应用

本文详细解析了线性混合效应模型在重复测量数据分析中的应用,并提供了SPSS操作指南。文章阐述了该模型如何通过区分固定效应与随机效应,有效处理数据非独立性和缺失值问题,从而获得更可靠的统计推断。

oo7890的博客 575

汽车TSN时间敏感网络测试技术与探索系列讲座4 -TSN802.1AS同步要求及验证方法

TSN网络各设备类型同步性能要求是什么?各类设备的测试组网及测试内容。也将通过演示来展示相关测试结果,及如何解决上述的测试关注点。

weixin_43903833的博客 765

[Easy] 125. Valid Palindrome

125. Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, we define empty string as valid palindrome. Example 1: Input: "A man, a plan, a canal

Bungehurst 161

全国职业院校技能大赛-大数据应用赛项-数据挖掘-01

-----------------------推荐Top5结果如下--------------------------------------------第一条数据前10列结果展示为:----------------------------------------相同种类前10的id结果展示为:--------------------相似度top5(商品id:14,平均相似度:0.522356)相似度top1(商品id:1,平均相似度:0.983456)若属于该spu_id,则内容为1否则为0。

Eternity_04的博客 1961

125. Valid Palindrome(easy)

Easy 5401519FavoriteShare Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note:For the purpose of this problem, we define empty str...

SourDumplings的博客 122

硬核实操!DeepSeek 携手 PCB 设计软件,自然语言绘就电路蓝图

摘要:本文深入探讨如何将 DeepSeek 与 PCB 设计软件对接,实现自然语言生成 PCB 电路图。文中详细阐述了从搭建对接架构,借助 Python 开发中间接口、适配数据格式,到自然语言处理,完成语义解析、知识匹配推理;再到生成 PCB 电路图,涵盖原理图与设计数据转化;最后对电路图进行优化与验证,包含布局布线优化和设计规则检查。尽管面临自然语言理解和复杂电路设计等挑战,但通过实操展示了技术可行性,为电子 / 嵌入式开发智能化设计提供新思路和完整实操指南。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 4837

【系统架构设计师】论文:论虚拟现实技术的应用与发展

虚拟现实技术是当前科学研究的热点,同时也是国家大力支持发展的核心技术之一。所谓虚拟现实,就是通过计算机等虚拟手段来构造一个非常接近真实世界的虚拟环境,它主要体现在视觉、触觉、嗅觉等方面的逼真模拟来达到高度的沉浸性,也就是如我们通常所说的“身临其境”。

数据知道的博客 1万+

LeetCode - Easy - 125. Valid Palindrome

Topic String Two Pointers Description https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, we define empty str

KISS 199

从零开始理解Linux中断架构(1)-前言

前段时间在转行手撸WIFI路由器,搞wifi路由器需要理解网络驱动程序,以太网卡驱动程序,无线WIFI驱动程序,而网卡驱动的关键路径就在中断程序中,需要了解NIC设备驱动程序如何收发数据,为了彻底的知道数据包是如何二层传递上来的,又需要了解一点Linux中断系统。第一次看到这张表是无感的,大概能够看懂的就是那个中断次数,因为不停的cat,这个数值会一直不停的增加。第一列是逻辑中断号,第二三列是中断次数,第四列是中断控制器的名字,第五列是硬件中断号,第六列 中断类型,第七列是 中断源关联设备。

maxleng的专栏 884

【leetcode】125.(Easy)Valid Palindrome

解题思路: 双指针 时间复杂度:O(n) 提交代码: class Solution { public boolean isPalindrome(String s) { int p1=0,p2=s.length()-1; while(p1&lt;p2) { while(!isChar(s.charAt(p1))&amp;&amp;p1&lt;p2) ...

AXIMI的博客 147

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Leet Code OJ 125. Valid Palindrome [Difficulty: Easy]

题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, “A man, a plan, a canal: Panama” is a palindrome. “race a car” is not

Lnho的专栏 3147

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

leetcode 125. Valid Palindrome (easy)

学习到了几种stl的用法 transform(b1,e1,b2,op) 按op的规则将b1,e1范围内的元素筛选到b2 prev(it) 获取it的前一个迭代器,对应的是distance() isalnum(char) 判断是否是字母or数字 isalpha(char) 判断是否是字母 这题要注意数字也算在要被识别的范围内 class Solution { public: bool isPali...

Rh's blog 145

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

125. Valid Palindrome - Easy

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note:For the purpose of this problem, we define empty string as valid palindrome. Examp...

weixin_34395205的博客 97

Leetcode 125. Valid Palindrome (Easy) (cpp)

Leetcode 125. Valid Palindrome (Easy) (cpp)

还是需要多学习!闷声大发财,这是坠吼的! 374

【LeetCode】 125. Valid Palindrome 验证回文串(Easy)(JAVA)

【LeetCode】 125. Valid Palindrome 验证回文串(Easy)(JAVA) 题目地址: https://leetcode.com/problems/valid-palindrome/ 题目描述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this

qq_16927853的博客 173

【python】leetcode 125. Valid Palindrome (easy)

125. Valid Palindrome (easy) Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, we define empty str...

momottyy的专栏 181

Easy-题目60:125. Valid Palindrome

题目原文: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. 题目大意: 给一个字符串,只考虑字母数字且忽略大小写的情况下,判断是不是回文的。 题目分析: 在普通判断回文的算法基础上简单加以改进即可,遇到大写字母转换为小写

232

Leet Code OJ 125. Valid Palindrome [Difficulty: Easy] -python

题目: 125.Valid Palindrome Easy Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note:For the purpose of this problem, we define empty string as valid palindrome. Example 1: Input: "A man,..

渣渣琪的博客 242

LeetCode-Easy部分中标签为Two Pointers 125. Valid Palindrome

判断一个字符串是不是`回文` 字符串。首、尾指针分别指向有效字符或数字,一一比较,若过程中出现不等,直接返回false,若两个指针碰头了,表示字符首、尾都相等,返回true。

相信相信的力量 949
上一篇: 【Medium】139. Word Break
下一篇: 【Easy】1. Two Sum
shirleyleychen
博客等级 码龄10年 0粉丝 19原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值