标签:
写了2个小时左右的代码。。打算把代码提交到github,发现校园网竟然上不去github了!!明明写代码之前我还上去的,害的我提交了好几次代码出问题,,还以为是VS出了问题,,要不就是自己的代码太厉害把github刺激崩溃了o(^▽^)o
既然上不去,干脆也不想写代码了,,去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.
1 class Solution { 2 public: 3 bool isAlphanumberic(char a) {//判断是否是数字或者字母 4 if(a >= 48 && a <= 57 || 5 (a >= 65 && a <= 90) || 6 (a >= 97 && a <= 122)) 7 return true; 8 return false; 9 } 10 bool isPalindrome(string s) { 11 if(s.size() == 0 ) 12 return true; 13 int start = 0; 14 int end = s.size() - 1; 15 while(start < end) { 16 if(isAlphanumberic(s[start]) && isAlphanumberic(s[end]) ){ 17 if(s[start] >= 97) 18 s[start] -= 32; 19 if(s[end] >= 97) 20 s[end] -= 32; 21 if(s[start] != s[end]) { 22 return false; 23 }else { 24 start ++; 25 end --; 26 } 27 }else if(!isAlphanumberic(s[start])){ 28 start ++; 29 }else if(!isAlphanumberic(s[end])) { 30 end --; 31 } 32 } 33 return true; 34 35 } 36 };
标签:
原文地址:http://www.cnblogs.com/zongmeng/p/4373513.html