码迷,mamicode.com
首页 > 其他好文 > 详细

Valid Palindrome

时间:2014-10-14 17:21:39      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   sp   div   

 

 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

标签:style   blog   color   io   os   ar   for   sp   div   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!