首页 > 其他 > 详细

Valid Palindrome

时间:2014-10-14 17:02:50      阅读:224      评论:0      收藏:0      [点我收藏+]

 

 1 class Solution {
 2 public:
 3     bool isPalindrome(string s) {
 4         int strLen = s.size();
 5         int pos_h = 0;
 6         int pos_t = 0;
 7         char *copy = new char[strLen];
 8         int num = 0;
 9         for(int i=0;i<strLen;i++)
10         {
11             if(s[i] >= 65 && s[i]  <= 90 || s[i] >= 48 && s[i] <= 57)
12               {
13                   *(copy+num) = s[i];
14                   num++;
15               }
16               else if(s[i] >= 97 && s[i]  <= 122)
17               {
18                   *(copy+num) = s[i] - 32;
19                   num++;
20               }
21         }
22        if(num == 0 || num == 1)
23             return true;
24         pos_h = 0;
25         pos_t = num - 1;
26         for(int i=0;i<num/2;i++)
27             {
28                if(copy[pos_h] != copy[pos_t])
29                     break;
30                pos_h++;;
31                pos_t--;
32             }
33             if(pos_h < pos_t )
34                 return false;
35             else
36                 return true;
37     }
38 };

 

Valid Palindrome

原文:http://www.cnblogs.com/ZhangYushuang/p/4024537.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!