当前位置:网站首页>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)
边栏推荐
猜你喜欢

动态数组底层是如何实现的

Cholesterol-PEG-Maleimide,CLS-PEG-MAL,胆固醇-聚乙二醇-马来酰亚胺一种修饰性PEG

Introduction of three temperature measurement methods for PT100 platinum thermal resistance

mmdetection/mmdetection3d多机多卡训练

基于层次分析法的“内卷”指数分析

leetcode 13. 罗马数字转整数

《中国综合算力指数》《中国算力白皮书》《中国存力白皮书》《中国运力白皮书》在首届算力大会上重磅发出

yarn详细入门教程

pyhon爬虫之爬取图片(亲测可用)

【web自动化测试】Playwright快速入门,5分钟上手
随机推荐
如何模拟后台API调用场景,很细!
小程序笔记3
Clearance sword refers to Offer——The sword refers to Offer II 010. and the sub-array of k
《机器学习的随机矩阵方法》
Matlab画图1
JS兼容问题总结
(1), the sequential storage structure of linear table chain storage structure
树莓派利用autofs自动挂载/卸载外部硬盘
框架整合(二)- 使用Apache ShardingSphere实现数据分片
Speech Recognition Learning Resources
The use of QCompleter for Qt auto-completion
要有遥不可及的梦想,也要有脚踏实地的本事
2022年五一数学建模C题讲解
mysqlbinlog 超过500g自动删除,保留7个,求大深给个版本
租房小程序登顶码云热门
【技术笔记】let 和 var和const的异同
DMPE-PEG-Mal,二肉豆蔻酰磷脂酰乙醇胺-聚乙二醇-马来酰亚胺简述
正则过滤字符串中 script 标签
The second step through MySQL in four steps: MySQL index learning
树莓派连接蓝牙音箱