Valid Palindrome [LeetCode]
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.
Solution:
bool isAlphanumberic(char a) {
if(a >= && a <= ||
(a >= && a <= ) ||
(a >= && a <= ))
return true;
return false;
}
bool isPalindrome(string s) {
if(s.size() == )
return true;
int start = ;
int end = s.size() - ;
while(start < end) {
if(isAlphanumberic(s[start]) && isAlphanumberic(s[end]) ){
if(s[start] >= )
s[start] -= ;
if(s[end] >= )
s[end] -= ;
if(s[start] != s[end]) {
return false;
}else {
start ++;
end --;
}
}else if(!isAlphanumberic(s[start])){
start ++;
}else if(!isAlphanumberic(s[end])) {
end --;
}
}
return true;
}
Valid Palindrome [LeetCode]的更多相关文章
- Valid Palindrome leetcode java
题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...
- Valid Palindrome ---- LeetCode 125
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 ignori ...
- [LeetCode]题解(python):125 Valid Palindrome
题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...
- [Leetcode][JAVA] Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 【LeetCode OJ】Valid Palindrome
Problem Link: http://oj.leetcode.com/problems/valid-palindrome/ The following two conditions would s ...
- LeetCode——Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [LeetCode] Valid Palindrome II 验证回文字符串之二
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...
- 【一天一道LeetCode】#125. Valid Palindrome
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
随机推荐
- VMware ESXI5.0的安装配置 zz
http://www.hotxf.com/thread-297-1-1.html 1, Vmware ESXI 光盘一张文件大小290M,本教程是以 5.0为案例. 2, 所需要安装的操作 ...
- Nessus基本命令
/etc/init.d/nessusd start 启动nessusd服务 默认端口8834 添加用户(未知是什么用户) sudo /opt/nessus/sbin/nessus-adduser
- [SAP ABAP开发技术总结]SD销售订单定价过程
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- CUBRID学习笔记 13 日志文件
欢迎转载 ,转载时请保留作者信息.本文版权归本人所有,如有任何问题,请与我联系wang2650@sohu.com . 过错 CUBRID Broker Log Files 可以理解为数据库中间件日志 ...
- 关于【bootstrap modal 模态框弹出瞬间消失的问题】
前提是你没有重复引入bootstrap.js\bootstrap.min.js和modal.js.一下提供一个小例子. <button class="btnbtn-primary bt ...
- iOS - UIImageView
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIImageView : UIView @available(iOS 2.0, *) public class U ...
- SAP屠夫---折旧在13-16调整期间的烦恼(转)
"应尽量避免在13-16期的折旧行为",在去年新准则ERP调整时就强调过,实际上, 有的企业并不使用13-16期间, 假设某家企业将折旧折在13期, 非常可惜的是,sap的折旧费用 ...
- ubuntu_ar命令(操作 ?.deb文件)
1. -x 从自备存文件中取出成员文件. 1.1. “root@zc33-desktop:/home# ar -x libstdc++6_4.7.2-5_i386.deb” 这样的话,它会把 lib ...
- [转载] Docker网络原则入门:EXPOSE,-p,-P,-link
原文: http://dockone.io/article/455 如果你已经构建了一些多容器的应用程序,那么肯定需要定义一些网络规则来设置容器间的通信.有多种方式可以实现:可以通过--expose参 ...
- [LED]如何配置LCD背光和LED,调试方法
[DESCRIPTION] 如何配置LCD背光和LED,调试方法 [SOLUTION]LCD背光和LED配置文件alps/custom/<proj name>lk/cust_leds.ca ...