This is a good question to ask during an interview. For the purpose of this problem, we define empty string as valid palindrome. SOLUTION 1: 左右指针往中间判断。注意函数: toLowerCase View Code SOLUTION 2: 引自http://blog.csdn.net/fightforyourdream/article/details/12860445的解答,会简单一点...
class Solution { public boolean isPalindrome(String s) { StringBuffer sgood = new StringBuffer(); int length = s.length(); for (int i = 0; i < length; i++) { char ch = s.charAt(i); if (Character.isLetterOrDigit(ch)) { sgood.append(Character.toLowerCase(ch)); } } String...
This is a good question to ask during an interview. For the purpose of this problem, we define empty string as valid palindrome. 思路: easy. AC代码: 1classSolution {2public:3boolisPalindrome(strings) {4inta=0,b=s.size()-1;5while(a<b){6if(!((s[a]>='a'&&s[a]<='z')||(s...
[LeetCode]Valid Palindrome Question 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. Not...
isValid(s[right])) { right--; continue; } if (s[left] === s[right]) { left++; right--; } else { break; } } return right <= left;};C++ Code:class Solution {public: bool isPalindrome(string s) { if (s.empty()) return true; const char*...
class Solution { public boolean isPalindrome(String s) { int st = 0; int ed = s.length() - 1; s = s.toLowerCase(); while (st < ed) { while (st < s.length() && !Character.isLetterOrDigit(s.charAt(st))) st++; while (ed >= 0 && !Character.isLetterOrDigit(s.charAt(ed...
classSolution:defvalidPalindrome(self,s:str)->bool:# 定义左指针 l ,初始化为 0l:int=0# 定义右指针 r ,初始化为 s.length - 1r:int=len(s)-1# 当还有字符需要比较时,继续处理whilel<r:# 如果 s[l] 和 s[r] 不相等,则需要删除字符ifs[l]!=s[r]:# 如果删除 左指针 或 右指针 指向的字...
classSolution:# @param s, a string# @return a booleandefisPalindrome(self, s):ifnots:returnTrues = s.lower() cl =0cr = len(s)-1whilecl <= cr:ifnots[cl].isalnum(): cl +=1continueifnots[cr].isalnum(): cr -=1continueifs[cl] != s[cr]:returnFalsecl +=1cr -=1returnTrue ...
1、注意空字符串的处理; 2、注意是alphanumeric字符; 3、字符串添加字符直接用+就可以; 1classSolution:2#@param s, a string3#@return a boolean4defisPalindrome(self, s):5ret =False6s =s.lower()7ss =""8foriins:9ifi.isalnum():10ss +=i11h =012e = len(ss)-113while(h<e):14if(ss...
1616.Split-Two-Strings-to-Make-Palindrome (M+) 1754.Largest-Merge-Of-Two-Strings (M+) 1849.Splitting-a-String-Into-Descending-Consecutive-Values (M+) 2468.Split-Message-Based-on-Limit (H-) Abbreviation 408.Valid-Word-Abbreviation (M) 411.Minimum-Unique-Word-Abbreviation (H) 527.Word-Abbre...