leetcode 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.

Note: For the purpose of this problem, we define empty string as valid palindrome.

Example 1:

Input: “A man, a plan, a canal: Panama”
Output: true
Example 2:

Input: “race a car”
Output: false

判断一个字符串是不是有效的回文字符串,忽略字母和数字以外的字符

思路:
双指针,指向头尾,然后向中间移
注意:
(1). 不区分大小写
(2). 中间有连续的非字母数字的字符,需要用while来跳过而不是if
(3). 要判断字母和数字

    public boolean isPalindrome(String s) {
        if (s == null || s == "") {
            return true;
        }
        
        int start = 0;
        int end = s.length() - 1;
        String str = s.toLowerCase();
        
        while(start < end) {
            while (start < end && !isAlpha(str.charAt(start))) {
                start ++;
            }
            
            while (start < end && !isAlpha(str.charAt(end))) {
                end --;
            }
            
            
            if(str.charAt(start) != str.charAt(end)) {
                return false;
            }
            start ++;
            end --;
        }
        
        return true;
    }
    
    public boolean isAlpha(char ch) {
        if ((ch >= 97 && ch <= 122) || (ch >= '0' && ch <= '9')) {
            return true;
        }
        
        return false;
    }
[leetcode]Valid Palindrome (判断回文数 C语言实现) 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” is a palindrome. “race a 阅读详情

相关推荐

Leetcode 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. Examp...

Top5软件工程硕士,先后在京东、字节从事多年Java后端开发、实时和离线大数据开发 526

【LeetCode】- Valid Palindrome(正确的回文)

[ 问题: ] Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. 直译:给你一个字符串, 判定它是否是回文(只统计字母、数字,其他字符请忽略)。

技术人生 5484

华为私有云HCS 8.1.1实战:从镜像制作到云主机发放全流程指南

本文详细解析了华为私有云HCS 8.1.1从镜像制作到云主机发放的全流程实战指南。内容涵盖制作标准化QCOW2镜像、配置云主机规格与主机组、规划外部网络,以及在运营面为租户初始化资源、配置审批流与产品目录。最后,通过用户视角演示了从创建VPC网络到申请、审批并最终绑定EIP访问云主机的完整操作步骤,为运维人员和架构师提供了一套清晰、可落地的HCS部署与管理实践方案。

weixin_29305313的博客 1140

Leetcode: Valid Palindromic

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 car” i

ayst123 的专栏 463

普通人如何上岸华为OD-面试总结

总共有3道算法题,100分值的两道,200分值的一道,不同的毕业院校和专业,通过机试的分值不一样,最少需要150分通过,提前和hr联系,了解自己需要多少分通过。重中之重:哪怕你是背的题库,也请你一定不要直接抄原来的,最好是变更下方法名,否则会判定你重复率过高,从而失去后面的面试机会(实在是不会做再用此方法,凑分数所用,面试官能看到你的代码,会影响你的面试评价)本人女,所以还问道了婚育计划,有对象这点可以说,没有问题,但是如果可以的话,生孩子的时间,可以给hr说这几年不考虑。如果说没有难题,直接就挂了。

weixin_47767264的博客 5493

西门子Industrial Copilot实战:5个工业场景下的AI效率提升案例

本文通过五个工业场景实战案例,深入解析西门子Industrial Copilot如何将工业智能转化为实际生产力。从自动化配置、预测性维护到能源优化与人机交互,这位AI助手显著缩短工程周期、提升设备可用率并降低运营成本,展示了其在工业领域系统化、工程化的落地价值。

3c4x5z6v7b的博客 940

【字符串回文】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" is a palindrome. "race a car" is not a

Wu_George的专栏 600

FPGA实现CAN接口(SJA1000)

学无止境,善于积累,每天积累一点点,成功就在眼前,加油! 1 CAN总线简介 CAN(Controller Area Network,控制器局域网 )总线是一个多主机异步串行总线,也是国际上应用最广泛的现场总线之一。在现场总线中,它是惟一被ISO国际标准化组织批准的现场总线。由于其成本低、容错能力强、支持分布式控制、通信速率高等优点在汽车、工业控制、航天等领域得到广泛应用。特别是由于CAN总线具有...

m0_46498597的博客 1万+

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" is a palindrome. "race a car" is not a

691

56、Cortex - M33处理器浮点单元(FPU)的使用与优化

本文详细介绍了Cortex-M33处理器浮点单元(FPU)的使用与优化方法,涵盖单双精度浮点计算的选择、编译器命令行配置、ABI模式对比、特殊FPU模式设置(如Flush-to-Zero、Default NaN)、浮点异常处理机制以及FPU电源管理策略。结合代码示例和流程图,提供了在不同应用场景下的最佳实践建议,并总结了常见问题及解决方案,帮助开发者提升嵌入式系统中浮点运算的性能、精度与能效。

bread的博客 165

我用 Python 监听了自己的键盘,生成击键热力图,看看每天到底在“摸鱼”还是“搬砖”?

数据采集(监听)、持久化(I/O)与可视化展示,必须是三个完全独立的模块,这符合单一职责原则。在多线程读写 Python 字典时,锁住的时间要尽可能短,防止 I/O 线程把高频的监听线程阻塞住。这类涉及底层的代码与“键盘记录木马”只有一线之隔。永远不要把击键记录通过网络上传,所有数据必须localhost消化。人脑对枯燥的 JSON 日志是不敏感的,但对颜色和空间极其敏感。这也是为什么 Prometheus + Grafana 是标配。使用ctypes。

BUG猿的博客 200

125 Valid Palindrome

题目链接:https://leetcode.com/problems/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:

再见了,过去的名字,新的奋斗开始啦! 1581

(五)C++自制植物大战僵尸游戏LoadingScene的实现讲解

游戏启动后就会立即切换到游戏加载场景中。只有游戏资源文件加载完成后,才能进入游戏。Loadingscene类继承Cocos2d-x中的Scene父类,表明Loadingscene是一个场景类。切换到LoadingScene场景中,首先会创建该场景,会调用函数,在该函数中调用自己定义的方法实现指定功能。代码文件的位置如下图所示。

尔灵尔亿的博客 2014

Java.lang.Character.isDigit()和isLetter()方法

[LeetCode]–125. Valid Palindrome在这个题里面遇到一个没见过判断字符串是否为字母啊数字的方法。这里解释一下。使用isDigit判断是否为数字public static boolean isNumeric(String str){ for (int i = str.length();--i&gt;=0;){ if (!Character.isDigit(...

qinhun0106的博客 605

一文搞定离线环境下的RAG引擎部署

在人工智能浪潮下,技术已成为构建智能问答、文档分析和代码助手等应用的核心。然而,在许多企业场景中,出于数据安全和性能的考虑,服务器往往部署在中,并要求极致的推理效率。这给依赖外部资源的应用部署带来了巨大挑战。如何在这种严苛的环境下,完整、可靠地部署一套包含向量数据库、**高性能推理服务(vLLM)**和Python后台的复杂RAG系统呢?本文将为你提供一个,手把手教你如何使用 Docker 技术,将一套基于 Weaviate 和的 Python RAG 应用完整打包,并在离线环境中一键部署。

木鱼时刻的专栏 1253

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

LeetCode125—Valid Palindrome

LeetCode125—Valid Palindrome

上善若水 808

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

LeetCode 125. Valid Palindrome 题解

本题是双指针的经典应用问题,主要考察对字符串处理和双指针技巧的理解和使用。通过使用双指针,我们可以高效地验证一个字符串是否是回文串。双指针的核心思想是:一个指针从字符串的开始位置,一个指针从字符串的结束位置,跳过非字母和数字字符,比较两个指针指向的字符是否相同,忽略大小写。这种方法不仅适用于验证回文串问题,还可以应用于许多其他需要比较字符串前后字符的场景。掌握双指针的使用,对于解决这类问题非常重要。

cannonjinx的博客 4170

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

【leetcode】(python) 125. Valid Palindrome有效回文

有效回文DescriptionExample题意解题思路code 125. Valid Palindrome Easy Description Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purp...

。 349

LeetCode 125. Valid Palindrome

题目来源:https://leetcode.com/problems/valid-palindrome/ 问题描述 125.Valid Palindrome Easy Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. ...

da_kao_la的博客 145

【leetcode】125. 验证回文串( Valid Palindrome )

题目描述 【leetcode】125. 验证回文串( Valid Palindrome ) 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。 说明:本题中,我们将空字符串定义为有效的回文串。 第一次解答 思路: 获取字符串左右值,若为字母和数字则比较(忽略大小写) 若不是目标字符,继续往中间获取 注意: s.size() == 0 test case: “A m...

Liber-coder的博客 249

LeetCode刷题:125. Valid Palindrome

LeetCode刷题:125. Valid Palindrome 原题链接:https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. N...

梅森上校的博客 业精于勤荒于嬉,形成于思毁于随。 188

LeetCode 125 Valid Palindrome(有效回文)(*)

翻译给定一个字符串,确定它是否是回文的,仅仅考虑其中的数字和字符并忽略其他。例如, “A man, a plan, a canal: Pannama” 是回文的。 “race a car” 不是回文的批注: 你是否考虑了字符串可能为空?这种面试的时候是一个好问题。对于这问题的意图,我们定义空字符串是回文的。原文Given a string, determine if it is a palindro

nomasp 4083

LeetCode125. Valid Palindrome 验证回文串

题目描述 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。 说明:本题中,我们将空字符串定义为有效的回文串。 示例 1: 输入: “A man, a plan, a canal: Panama” 输出: true 示例 2: 输入: “race a car” 输出: false 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/p...

it-hao的博客 283

【leetCode】leetCode125 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. ...

随手积累,典型bug解决。技术栈的系统介绍。 196

125. Valid Palindrome*

125. Valid Palindrome* 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 ...

珍妮的选择的博客 240

[Leetcode] 125. Valid Palindrome

Problems: https://leetcode.com/problems/valid-palindrome/ Solution: class Solution { public boolean isPalindrome(String s) { // 将字符小写化 String ls = s.toLowerCase(); // 删除不是数字/字...

Renoler的博客 115
上一篇: leetcode 235, 236. Lowest Common Ancestor of a Binary Search Tree(二叉树的最低共同祖先)
下一篇: leetcode 404. Sum of Left Leaves (左叶子的和)
蓝羽飞鸟
博客等级 码龄8年 1万+粉丝 727原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝羽飞鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值
⌂ 换网址