当前位置:网站首页>018. Valid palindromes
018. Valid palindromes
2022-07-06 09:34:00 【Prism 7】
List of articles
One 、code
1.1 Title Description
1.2 Answer key
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;
}
}
Two 、 summary
String class :
- s.charAt() Method to return the characters at the specified index . Index range is from 0 To length() - 1.
Character class :
- Character.isLetterOrDigit() // Judge is character or Numbers
- Character.isLowerCase()/Character.isUpperCase() // Determine case
-Character.toLowerCase()/Character.toUpperCase() // Convert case
边栏推荐
- 五月集训总结——来自阿光
- IDS cache preheating, avalanche, penetration
- Five layer network architecture
- Kratos战神微服务框架(三)
- How to intercept the string correctly (for example, intercepting the stock in operation by applying the error information)
- leetcode-14. Longest common prefix JS longitudinal scanning method
- 基于WEB的网上购物系统的设计与实现(附:源码 论文 sql文件)
- Basic usage of xargs command
- Mapreduce实例(十):ChainMapReduce
- Design and implementation of online shopping system based on Web (attached: source code paper SQL file)
猜你喜欢
Advanced Computer Network Review(5)——COPE
Use of activiti7 workflow
小白带你重游Spark生态圈!
Redis之Bitmap
Persistence practice of redis (Linux version)
MapReduce instance (IV): natural sorting
Reids之缓存预热、雪崩、穿透
[shell script] - archive file script
The carousel component of ant design calls prev and next methods in TS (typescript) environment
[deep learning] semantic segmentation: paper reading: (2021-12) mask2former
随机推荐
LeetCode41——First Missing Positive——hashing in place & swap
Oom happened. Do you know the reason and how to solve it?
Redis之Bitmap
Kratos战神微服务框架(一)
Detailed explanation of cookies and sessions
【深度学习】语义分割-源代码汇总
[deep learning] semantic segmentation: paper reading: (2021-12) mask2former
Redis' bitmap
Parameterization of postman
Kratos ares microservice framework (II)
五月刷题27——图
Mapreduce实例(七):单表join
[daily question] Porter (DFS / DP)
How to intercept the string correctly (for example, intercepting the stock in operation by applying the error information)
QML type: overlay
五月刷题02——字符串
Redis之五大基础数据结构深入、应用场景
Advanced Computer Network Review(5)——COPE
Improved deep embedded clustering with local structure preservation (Idec)
Seven layer network architecture