LeetCode_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.
class Solution {
public:
bool check(char test, char & c)
{
if(test >= 'a' && test <= 'z')
{
c = test;
return true;
}else if(test >= 'A' && test <= 'Z'){
c = test - 'A' + 'a';
return true;
}else if (test >= '' && test <= ''){
c = test;
return true;
}
return false;
}
bool isPalindrome(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int j = s.length();
if(j-- == ) return true;
int i = ; char head,tail;
while(i<j){
while(i<j){
if(check(s[i],head)) break;
i++;
}
if(i>=j) return true;
while(i<j){
if(check(s[j], tail)) break;
j--;
}
if(i>=j) return true;
if(head != tail ) return false;
i++;j--;
}
return true ;
}
};
LeetCode_Valid Palindrome的更多相关文章
- 【leeetcode】125-Valid Palindrome
problem 125. Valid Palindrome 参考 1. Leetcode_Valid Palindrome; 完
- PALIN - The Next Palindrome 对称的数
A positive integer is called a palindrome if its representation in the decimal system is the same wh ...
- [LeetCode] Longest Palindrome 最长回文串
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- [LeetCode] Palindrome Pairs 回文对
Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- [LeetCode] Palindrome Linked List 回文链表
Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time ...
- [LeetCode] Shortest Palindrome 最短回文串
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- [LeetCode] Palindrome Partitioning II 拆分回文串之二
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
随机推荐
- 从点击Button到弹出一个MessageBox, 背后发生了什么(每个UI线程都有一个ThreadInfo结构, 里面包含4个队列和一些标志位)
思考一个最简单的程序行为:我们的Dialog上有一个Button, 当用户用鼠标点击这个Button时, 我们弹出一个MessageBox. 这个看似简单的行为, 谁能说清楚它是如何运行起来的,背 ...
- VC的话有必要认真听,但却不用急着照办
本文来自著名风险投资人 Fred Wilson 的博客 AVC,他在 2016 年 8 月 23 日的这篇文章<Understanding VCs>里用简单的语言揭秘了 VC(风险投资人) ...
- 【转】64位win7硬盘安装64位ubuntu 13.04
原文网址:http://www.cnblogs.com/jiangz/p/3751617.html 最近本来是准备通过升级的方式把ubuntu从12.04升级到12.10再升级到13.04的,但是升级 ...
- 【活动】明星衣橱CEO林清华聊创业 | 猎云网
[活动]明星衣橱CEO林清华聊创业 | 猎云网 [活动]明星衣橱CEO林清华聊创业
- 获取java类和方法名
String clazz = this.getClass().getName(); String method = Thread.currentThread() .getStackTrace()[1] ...
- c语言编程之sglib库的简单使用
说实话自从大学毕业后已经很久没有用c语言写过程序了,一般都是使用c++,c++的stl和boost等,这些代码库大大简化了我们的编程复杂度.由于最近某种原因在次开始用c写程序.我是个比较懒的人,比较喜 ...
- [置顶] Android安全机制分析
Android系统是基于Linux内核开发的,因此,Android系统不仅保留和继承了Linux操作系统的安全机制,而且其系统架构的各个层次都有独特的安全特性[2] . 1. Linux内核层安全机制 ...
- IE常见的CSS的BUG(一)
2011年6月,我毕业了.2012年我接触了CSS,本以为会好过些能赚点钱了,可谁知,Internet Explorer(下称IE),这个前端工程师的噩梦浏览器让我不再那么好过了.各种出现在IE身上的 ...
- Ajax:Cross-Origin Resource Sharing(转)
实例:http://blog.csdn.net/hongweigg/article/details/39054403 通过XHR实现Ajax通信的一个主要限制,来源于跨域安全策略.默认情况下,XHR对 ...
- Java数据结构漫谈-Stack
Stack(栈)是一种比较典型的数据结构,其元素满足后进先出(LIFO)的特点. Java中Stack的实现继承自Vector,所以其天然的具有了一些Vector的特点,所以栈也是线程安全的. cla ...