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 阅读详情

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.

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:

输入: "A man, a plan, a canal: Panama"
输出: true

示例 2:

输入: "race a car"
输出: false

算法设计

package com.bean.algorithm.basic;

public class ValidPalindrome {

	public static boolean isPalindrome(String input) {
		input = input.toLowerCase();
		input = input.replaceAll("[^0-9a-zA-Z]", "");

		int j = input.length();
		for (int i = 0; i < input.length(); i++) {
			String fword = input.substring(i, i + 1);
			String lword = input.substring(j - 1, j);
			if (!fword.equals(lword)) {
				return false;
			}
			if (i == j) {
				return true;
			}
			j--;
		}

		return true;

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		/*
		 * Input: "A man, a plan, a canal: Panama"
		 * Output: true
		 */
		ValidPalindrome validPalindrome=new ValidPalindrome();
		String input="A man, a plan, a canal: Panama";
		boolean flag=validPalindrome.isPalindrome(input);
		System.out.println("Flag is: "+flag);
		
	}

}

程序运行结果:

Flag is: true

Python微信小程序竞赛报名管理系统开发全流程:从架构到上线避坑指南 微信小程序开发已成为数字化转型中高频出现的技术需求,尤其在校园赛事、企业内部流程管理等场景中,通过轻量级前端与Python后端配合,能快速搭建高效的业务管理系统。理解前后端分离的架构原则,掌握RESTful API的设计与调试方法,是保障项目稳定性的关键。数据库表结构设计、文件上传与安全校验、基于token的登录态管理,则是开发过程中最容易踩坑的环节。本文结合竞赛报名管理系统的真实开发经验,从Flask框架的使用、uni-app多端编译到接口联调与上线自检,系统梳理了完整的技术链路,并给出大量可直接复用的工 阅读详情

相关推荐

最全软考高项工具技术总结(上)

第四版教材把工具和技术分为:数据收集技术、数据分析技术、数据表现技术、决策技术、沟通技巧、人际关系和团队技能、其他。我会按照上面的分类总结说明并标识他们用在哪些过程。小伙伴们可以通读理解做到有印象能选对应付上午选择,选几个深化用在下午论文的举例中。没必要背!

PM喵的窝 2052

leetcode刷题日记:125. Valid Palindrome(验证回文串)和136. Single Number(只出现一次的数字)

验证一个串之前我们需要对字符串进行处理将空格逗号什么的去掉,然后进行比较,比较的顺序如图所示:在比较途中如果出现比较结果为假,就提前结束比较,此时我们可以判断这一个串不是回文串,反之如果没有提前结束,那就是回文串。

apprentice_eye的博客 209

NVIDIA DGX Spark实战指南:从开箱到AI模型高效部署

本文详细介绍了NVIDIA DGX Spark的开箱体验、硬件架构及AI模型高效部署实战指南。从1 PetaFLOP算力的迷你设备到Grace Blackwell超级芯片的深度解析,再到五分钟快速上手指南和大模型部署技巧,帮助开发者充分利用这款全球最小AI超级计算机的性能优势。

weixin_29239279的博客 1390

LeetCode 125. Valid Palindrome 题解

本题是字符串处理的经典问题。双指针技巧字符类型判断大小写处理边界条件处理通过本题可以深入理解双指针在字符串处理中的应用。

cannonjinx的博客 4178

vc formal实例

gui 方式启动命令,

weixin_45077935的博客 687

告别混乱!AutoSar BswM模式管理实战:手把手教你配置Rule与ActionList(附避坑指南)

本文详细解析了AutoSar BswM模式管理的实战配置,重点介绍了Rule与ActionList的高效组合方法,帮助开发者避免常见陷阱。通过具体案例演示了从基础到复杂的配置步骤,包括模式仲裁、逻辑表达式构建及ActionList优化策略,提升汽车电子系统的协调性与可靠性。

weixin_27066963的博客 266

LeetCode125—Valid Palindrome

LeetCode125—Valid Palindrome

上善若水 806

ArcGISPro应用指南:ArcGISPro制图全流程详解

本文介绍了基于ArcGIS Pro的地图制作基本流程,旨在帮助读者快速掌握从数据加载到地图输出的完整制图操作。文章首先简要概述了GIS技术在当今数据驱动时代的重要作用,并引出ArcGIS Pro作为专业GIS平台的优势与应用价值。随后,内容围绕地图制作的核心步骤展开,包括数据加载、布局创建、地图范围设置以及各类地图要素(如指北针、比例尺、图例、图名)的插入与样式调整。此外,还介绍了如何通过添加图形、文本及动态元素增强地图表达效果,并最终完成地图导出设置与文件输出格式的选择。

weixin_45812624的博客 1378

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

珍妮的选择的博客 239

Computer Networks 和 Computer & Security投稿经验

论文投稿

qq_50604294的博客 9284

uni-app - 刘海屏(Iphone X)底部横杠(——)白色区域块(安全距离处更改颜色)解决方案

场景:因为要做无tabbar页面,所以在配置文件中取消底部导航栏。取消后,iPhoneX(刘海屏)底部就出现如下图所示白色安全区域问题:这个问题,是因为uni-app默认会为iPhoneX(刘海屏)留出安全距离,这个安全距离的背景色就是白色。所以,如果你将页面颜色设置为其他颜色,就会与默认白色冲突。有2个不同的解决方案(原生占位),虽然原理是一样,但使用的场景不同,请根据您的需求来采纳。

🏆 前端领域优质创作者 1万+

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

RK3568项目(四)--uboot启动流程之启动模式选择

本章接着上面,接着来分析uboot启动流程,设计vendor、按键、驱动模式的选择等

文艺小少年的博客 590

【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

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

leetcode python3 简单题125. Valid Palindrome

1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百二十二题 (1)题目 英文:

从此做一个俗人 292

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

LeetCode--125. Valid Palindrome

题目链接:https://leetcode.com/problems/valid-palindrome/ 这是一道很简单平常的问题,但是非常的恶心,提交了6次才AC,主要是对alphanumeric characters的理解,它的定义参考https://whatis.techtarget.com/definition/alphanumeric-alphameric。知晓了这个定义就十分轻松了,...

To_be_thinking的博客 155

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

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

【LeetCode】125. Valid Palindrome

LeetCode125 传送门 解法比较简单: 两个指针,分别从左向右,从右向左遍历字符串,时间复杂度,空间复杂度。 Python源码: class Solution: def isPalindrome(self, s: str) -> bool: s = s.lower() left_p = 0 right_p = ...

weixin_42344158的博客 138

【leetcode】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 v...

lemonade13的博客 125

LeetCode 125 Valid Palindrome

LeetCode 125 Valid Palindrome Problem Description: 判断给出的字符串是否是有效的回文字符串。 具体的题目信息: https://leetcode.com/problems/valid-palindrome/description/ Solution: 解题思路:用两个变量i和j从字符串两端向中间移动,比较两个变量指向的字符 (1)如...

萤火虫啊飞呀飞 280

LeetCode: 125. Valid Palindrome

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

杨领well的专栏 700

[leetcode]125. Valid Palindrome

[leetcode]125. Valid Palindrome Analysis 周五啦周五啦,网上买的小南瓜到啦—— [六一快乐,嘻嘻~] Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: Fo...

weixin_32135877的博客 131

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

[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

【LeetCode125】Valid Palindrome

Runtime:8 ms, faster than85.46%ofC++online submissions forValid Palindrome. Memory Usage:9.4 MB, less than61.22%ofC++online submissions forValid Palindrome. class Solution { public: ...

weixin_39458342的博客 154

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
上一篇: LeetCode刷题:929. Unique Email Addresses
下一篇: LeetCode刷题:771. Jewels and Stones
梅森上校
博客等级 码龄22年 1095粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值