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

Clearance sword refers to Offer——The sword refers to Offer II 010. and the sub-array of k

《机器学习理论到应用》电子书免费下载

学习探索-给字体设置前景色

LeetCode Question of the Day - 1403. Minimum Subsequence in Non-Increasing Order

如何模拟后台API调用场景,很细!

微信jsApi调用失效的相关问题

《机器学习的随机矩阵方法》

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

RecyclerView 缓存与复用机制

框架整合(二)- 使用Apache ShardingSphere实现数据分片
随机推荐
darknet源码阅读笔记-02-list.h和lish.c
餐饮供应链管理系统
NLP未来,路在何方?从学术前沿和业界热点谈起
DMPE-PEG-Mal,二肉豆蔻酰磷脂酰乙醇胺-聚乙二醇-马来酰亚胺简述
clickhouse 上下线表
公司自用的国产API管理神器
集群监控——Zabbix使用
浅谈运用低代码技术如何实现物流企业的降本增效
如何模拟后台API调用场景,很细!
使用Redis做某个时间段在线数统计
88.(cesium之家)cesium聚合图
el-date-picker 设置时间范围
如何让 JS 代码不可断点
R语言计算时间序列数据的逐次差分(successive differences):使用diff函数计算时间序列数据的逐次差分值
最小区间覆盖
Flutter实战-请求封装(四)之gzip报文压缩
R语言ggpubr包的ggtexttable函数可视化表格数据(直接绘制表格图或者在图像中添加表格数据)、使用ggarrange函数将表格数据和可视化图像组合起来(表格数据在可视化图像下方)
】 【 LeetCode daily one problem - 540. The order of a single element of the array
Introduction of three temperature measurement methods for PT100 platinum thermal resistance
To eliminate asynchronous callbacks, it has to be async-await