当前位置:网站首页>018.有效的回文
018.有效的回文
2022-07-06 09:01:00 【棱镜7】
一、code
1.1 题目描述
1.2 题解
class Solution {
public boolean isPalindrome(String s) {
int i = 0;
int j = s.length() - 1;
while(i < j){
char ch1 = s.charAt(i);
char ch2 = s.charAt(j);
if(!Character.isLetterOrDigit(ch1)){
i++;
continue;
}
if(!Character.isLetterOrDigit(ch2)){
j--;
continue;
}
ch1 = Character.toLowerCase(ch1);
ch2 = Character.toLowerCase(ch2);
if(ch1 != ch2){
return false;
}
i++;
j--;
}
return true;
}
}
二、总结
String类:
- s.charAt() 方法用于返回指定索引处的字符。索引范围为从 0 到 length() - 1。
Character类:
- Character.isLetterOrDigit() //判断是字符or数字
- Character.isLowerCase()/Character.isUpperCase() //判断大小写
-Character.toLowerCase()/Character.toUpperCase() //转化大小写
边栏推荐
- Lua script of redis
- LeetCode41——First Missing Positive——hashing in place & swap
- [daily question] Porter (DFS / DP)
- 工作流—activiti7环境搭建
- Design and implementation of online shopping system based on Web (attached: source code paper SQL file)
- Global and Chinese markets for small seed seeders 2022-2028: Research Report on technology, participants, trends, market size and share
- 基于WEB的网上购物系统的设计与实现(附:源码 论文 sql文件)
- IDS cache preheating, avalanche, penetration
- [text generation] recommended in the collection of papers - Stanford researchers introduce time control methods to make long text generation more smooth
- 英雄联盟轮播图手动轮播
猜你喜欢
Redis之Geospatial
[oc]- < getting started with UI> -- common controls - prompt dialog box and wait for the prompt (circle)
Mathematical modeling 2004b question (transmission problem)
Redis之主从复制
Redis之持久化实操(Linux版)
Design and implementation of online shopping system based on Web (attached: source code paper SQL file)
Kratos ares microservice framework (II)
Redis之连接redis服务命令
Master slave replication of redis
Advanced Computer Network Review(3)——BBR
随机推荐
Redis之Lua脚本
Redis cluster
五层网络体系结构
Pytest参数化你不知道的一些使用技巧 /你不知道的pytest
Kratos战神微服务框架(三)
Global and Chinese market of bank smart cards 2022-2028: Research Report on technology, participants, trends, market size and share
基于B/S的影视创作论坛的设计与实现(附:源码 论文 sql文件 项目部署教程)
Reids之删除策略
Global and Chinese market of metallized flexible packaging 2022-2028: Research Report on technology, participants, trends, market size and share
[oc]- < getting started with UI> -- common controls uibutton
Redis之Geospatial
基于B/S的网上零食销售系统的设计与实现(附:源码 论文 Sql文件)
有软件负载均衡,也有硬件负载均衡,选择哪个?
Le modèle sentinelle de redis
为拿 Offer,“闭关修炼,相信努力必成大器
Redis core configuration
Pytest parameterization some tips you don't know / pytest you don't know
[shell script] use menu commands to build scripts for creating folders in the cluster
Advanced Computer Network Review(3)——BBR
Opencv+dlib realizes "matching" glasses for Mona Lisa