当前位置:网站首页>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)
边栏推荐
猜你喜欢
信息系统项目管理师必背核心考点(六十)项目集管理
化学制品制造业数智化供应链管理系统:打造智慧供应体系,赋能企业产效提升
框架整合(二)- 使用Apache ShardingSphere实现数据分片
Codeforces积分系统介绍
《机器学习的随机矩阵方法》
Boost library study notes (1) Installation and configuration
DSPE-PEG-DBCO,DBCO-PEG-DSPE,磷脂-聚乙二醇-二苯并环辛炔科研实验用
Learning to Explore - Setting the Foreground Color for Fonts
OpenInfra Days China 2022 | SelectDB to share with you the Apache Doris in Internet advertising business practices
【web自动化测试】Playwright快速入门,5分钟上手
随机推荐
NLP未来,路在何方?从学术前沿和业界热点谈起
荣耀互联对外开放,赋能智能硬件合作伙伴,促进全场景生态产品融合
学习探索-网站中引入百度统计
Thrift IDL示例文件
Matlab画图1
Speech Recognition Learning Resources
安装失败怎么办
消灭异步回调,还得是async-await
shell函数内如何调用另一个函数
小程序笔记2
CAS:385437-57-0,DSPE-PEG-Biotin,生物活性分子磷脂-聚乙二醇-生物素
基于大学生内卷行为的调查研究
localhost,127.0.0.1,本机IP
动态数组底层是如何实现的
R语言dplyr包group_by函数和summarise_at函数计算dataframe计算不同分组的计数个数和均值、使用%>%符号将多个函数串起来
租房小程序登顶码云热门
The second step through MySQL in four steps: MySQL index learning
正则过滤字符串中 script 标签
Flutter实战-请求封装(四)之gzip报文压缩
数字化金融企业的产品体系长啥样?