当前位置:网站首页>leetcode/有效的回文串,含有不需要判断回文的字符
leetcode/有效的回文串,含有不需要判断回文的字符
2022-08-04 17:43:00 【xcrj】
代码
package com.xcrj;
/** * 剑指 Offer II 018. 有效的回文串,含有其他字符 * 给定一个字符串 s ,验证 s 是否是 回文串 ,只考虑字母和数字字符,可以忽略字母的大小写。 */
public class Solution18 {
/** * 双指针相向移动 */
public boolean isPalindrome1(String s) {
int l = 0, r = s.length() - 1;
// !!!双指针相向移动模板
while (l < r) {
while (l < r && !Character.isLetterOrDigit(s.charAt(l))) l++;
while (l < r && !Character.isLetterOrDigit(s.charAt(r))) r--;
if (l < r) {
if (Character.toLowerCase(s.charAt(l)) != Character.toLowerCase(s.charAt(r))) return false;
l++;
r--;
}
}
return true;
}
public static void main(String[] args) {
Solution18 solution18 = new Solution18();
System.out.println(solution18.isPalindrome1("A--a"));
}
}
参考
作者:LeetCode-Solution
链接:https://leetcode.cn/problems/XltzEq/solution/you-xiao-de-hui-wen-by-leetcode-solution-uj86/
来源:力扣(LeetCode)
边栏推荐
- About the two architectures of ETL (ETL architecture and ELT architecture)
- 设置表头颜色
- 怎么招聘程序员
- "Involution" Index Analysis Based on AHP
- shell函数内如何调用另一个函数
- 88. (the home of cesium) cesium polymerization figure
- Thrift IDL Sample File
- 微信jsApi调用失效的相关问题
- 租房小程序登顶码云热门
- R语言glm函数使用频数数据构建二分类logistic回归模型,分析的输入数据为频数数据(多个分类指标对应的阴性样本和阳性样本的频数数据)、weights参数指定频数值
猜你喜欢

2022年五一数学建模C题讲解

关于ETL的两种架构(ETL架构和ELT架构)

88. (the home of cesium) cesium polymerization figure

【论文阅读】Decision Transformer: Reinforcement Learning via Sequence Modeling

Learning to Explore - Setting the Foreground Color for Fonts

【LeetCode Daily Question】——374. Guess the size of the number

公司自用的国产API管理神器

开发一套高容错分布式系统

Introduction of three temperature measurement methods for PT100 platinum thermal resistance

Clearance sword refers to Offer——The sword refers to Offer II 010. and the sub-array of k
随机推荐
【图像分类】2021-DeiT
要有遥不可及的梦想,也要有脚踏实地的本事
两个对象相同数据赋值
华为云计算HCIE之oceanstor仿真器的安装教程
如何模拟后台API调用场景,很细!
DMPE-PEG-Mal,二肉豆蔻酰磷脂酰乙醇胺-聚乙二醇-马来酰亚胺简述
使用bash语句,清空aaa文件夹下的所有文件
租房小程序登顶码云热门
88.(cesium之家)cesium聚合图
【日记】nodejs构建API框架以及RESTful API 和 JSON-RPC的取舍
软件测试高频面试题真实分享/网上银行转账是怎么测的,设计一下测试用例。
启动项目(瑞吉外卖)
CF86D Powerful array
localhost,127.0.0.1,本机IP
SRM供应商协同管理系统功能介绍
华为云计算HCIE之oceanstor仿真器的使用操作
Thrift IDL示例文件
Interval greedy (interval merge)
LeetCode 899. 有序队列
如何让 JS 代码不可断点