LeetCode(61)-Valid Palindrome
2024-10-11 22:38:10
题目:
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome.
Note:
Have you consider that the string might be empty? This is a good question to ask during an interview.
For the purpose of this problem, we define empty string as valid palindrome.
思路:
- 题意:判断一个字符串是不是回文
- 这道题可以采用双指针,开头first,结尾sed,first++,sed–,first < sed
- 要求不考虑大小写,全部转化为大写,同时判断字符是不是字母和数字,‘A’,‘Z’,‘0’,‘9’
代码:
public class Solution {
public boolean isPalindrome(String s) {
if(s == null){
return true;
}
char A = 'A';
char Z = 'Z';
char numMin = '0';
char numMax = '9';
s = s.toUpperCase();
int first = 0;
int sed = s.length() - 1;
while(first < sed){
if((s.charAt(first) < A||s.charAt(first) > Z) && (s.charAt(first) < numMin||s.charAt(first) > numMax)){
first++;
continue;
}
if((s.charAt(sed) < A||s.charAt(sed) > Z) && (s.charAt(sed) < numMin||s.charAt(sed) > numMax)){
sed--;
continue;
}
if(s.charAt(first) == s.charAt(sed)){
first++;
sed--;
}else{
return false;
}
}
return true;
}
}
最新文章
- 详解Linux目录(目录树详细解释)
- PMIC RTC 寄存器
- 关于MVC中模型model的验证问题
- android手势事件 快速移动 长按触摸屏 按下触摸屏,并拖动
- RPM命令用法详解
- svg 文字
- STM32定时器
- CSS 自动隐藏文字并添加省略号
- 团队作业4——第一次项目冲刺(Alpha版本)11.14
- Ubuntu如何使用Vscode写C++代码
- [翻译]一个新式的基于文本的浏览器 Browsh
- .net webapi跨域方法整理
- Unity 3D用简单的Cube、Sphere实现镜面/哈哈镜效果,只需十几秒哦!
- 通过汇编一个简单的C程序,分析汇编代码理解计算机是如何工作的
- 升级到AndroidStudio3.2.1的注意事项
- Xcode7安装CocoaPods
- iOS 11 使用方法替换(Method Swizzling),去掉导航栏返回按钮的文字
- T-SQL备份数据库恢复
- django drf django-filter的method过滤
- node中express的中间件之methodOverride
热门文章
- C语言实现简单黑客帝国代码流
- CSDN帐号被封
- JQuery之事件处理
- Linux Debugging(八): core真的那么难以追踪吗?
- android EventBus 3.0使用指南
- 最简单的基于Flash的流媒体示例:RTMP推送和接收(ActionScript)
- SQL 2012 Always On 为 MSCRMSqlClrLogin SQL 登录名创建非对称密钥时报语法错误
- 【一天一道LeetCode】#105. Construct Binary Tree from Preorder and Inorder Traversal
- 使用VideoView实现简单视频播放器
- volatile实现可见性但不保证原子性