当前位置:网站首页>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)
- JS中null与undefined的异同点
- pyhon爬虫之爬取图片(亲测可用)
- 软件测试高频面试题真实分享/网上银行转账是怎么测的,设计一下测试用例。
- 如何模拟后台API调用场景,很细!
- (1), the sequential storage structure of linear table chain storage structure
- 字节二面被问到mysql事务与锁问题,我蚌埠住了
- 第一章 对象和封装
- LeetCode Question of the Day - 1403. Minimum Subsequence in Non-Increasing Order
- 基于clipboard.js对复制组件的封装
猜你喜欢
微信jsApi调用失效的相关问题
软件测试高频面试题真实分享/网上银行转账是怎么测的,设计一下测试用例。
Introduction of three temperature measurement methods for PT100 platinum thermal resistance
Thrift IDL Sample File
[Web Automation Test] Quick Start with Playwright, 5 minutes to get started
SQL优化最全总结 - MySQL(2022最新版)
RecyclerView 缓存与复用机制
yarn详细入门教程
php如何查询字符串以什么开头
从-99打造Sentinel高可用集群限流中间件
随机推荐
面试官:可以谈谈乐观锁和悲观锁吗
OpenInfra Days China 2022 | SelectDB to share with you the Apache Doris in Internet advertising business practices
LeetCode 899. 有序队列
如何模拟后台API调用场景,很细!
CF86D Powerful array
从-99打造Sentinel高可用集群限流中间件
To eliminate asynchronous callbacks, it has to be async-await
NLP未来,路在何方?从学术前沿和业界热点谈起
Liunx删除乱码文件
小程序笔记3
The second step through MySQL in four steps: MySQL index learning
基于层次分析法的“内卷”指数分析
自定义组件,并在组件中注入自定义组件实现多种场景的下的组件切换
知乎高赞:拼多多和国家电网,选哪个?
【日记】mysql基本操作
PT100铂热电阻三种测温方法介绍
学习探索-网站中引入百度统计
如何让 JS 代码不可断点
CAS:385437-57-0,DSPE-PEG-Biotin,生物活性分子磷脂-聚乙二醇-生物素
JS中null与undefined的异同点