LeetCode(61)-Valid Palindrome
题目:
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;
}
}
LeetCode(61)-Valid Palindrome的更多相关文章
- [LeetCode] 680. Valid Palindrome II 验证回文字符串 II
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...
- [Leetcode][JAVA] Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [leetcode] 1. Valid Palindrome
leetcode的第一题,回文数判断. 原题如下: For example, "A man, a plan, a canal: Panama" is a palindrome. & ...
- LeetCode 1216. Valid Palindrome III
原题链接在这里:https://leetcode.com/problems/valid-palindrome-iii/ 题目: Given a string s and an integer k, f ...
- [LeetCode] 125. Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 【leetcode】Valid Palindrome
题目简述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...
- 【题解】【字符串】【Leetcode】Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- leetcode 125. Valid Palindrome ----- java
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- LeetCode 125. Valid Palindrome
这个题目只要注意大小写问题即可解决,而且我们只关注的是字母和数值 Given a string, determine if it is a palindrome, considering only a ...
随机推荐
- spring @Qualifier注解使用
@Autowired是根据类型进行自动装配的.如果当Spring上下文中存在多个UserDao类型的bean时,就会抛出BeanCreationException异常;如果Spring上下文中不存在U ...
- GraphX PageRank
GraphX算法模型:PageRank 一:算法介绍 PageRank是Google专有的算法,用于衡量特定网页相对于搜索引擎索引中的其他网页而言的重要程度. 一个页面的"得 ...
- Jetty 嵌入式启动官方完整教程
网上太多了,不如直接看官方的这个全面. http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty 入门地址: http://wiki.eclipse ...
- Description Resource Path Location Type AndroidManifest.xml file missing!
这个问题又找了好久.国内回答的确不敢恭维. 本回答来自谷歌: This is build issue. Go to Menu in eclipse, Project>clean then P ...
- 从一个简洁的进度刻度绘制中了解自定义View的思路流程
先看效果(原谅我的渣像素),进度的刻度.宽度.颜色可以随意设定: [项目github地址: https://github.com/zhangke3016/CircleLoading] 实现起来并不难, ...
- 百度的android面试总结分析
今天就是今天上午10点,我接到了百度的电话面试,当然提前和我说了,我的拖延症是有多强烈,以至于我没怎么准备,当然我也想着看看自己的真实水平,在此检讨一下!!!!!!!!!!!!!!!!!!!!!!!! ...
- Elcipse安装gradle插件
参考: http://www.gradle.org/docs/current/userguide/installation.html (1)下载Gradle 官网下载www.g ...
- (copy)赋值构造函数的4种调用时机or方法
第一种调用方法: demo #include <iostream> using namespace std; class Text { public: Text() // 无参数构造函数 ...
- 将项目Demo上传到Github上的操作步骤
之前我有很多代码直接上传到了CSDN上,主要是因为操作方便,今天我就说说将源码Demo上传到Github上的操作步骤. 首先,你要先确定自己在Github上有自己的账户名,账户邮箱和密码.如果没有可以 ...
- 今日成为CSDN认证专家
认证时写的申请材料: 程序猿一枚毕业于南开工作于上海.喜欢读书,喜欢跑步,激情似火,心静如水. 喜欢编程,喜欢寻根问底各种技术,喜欢在各种新技术中汲取营养. 喜欢分享,因此以一些高质量的博文来回报各位 ...