leetcode4 Valid Palindrome回文数

  Valid Palindrome回文数

  whowhoha@outlook.com

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.

解决方法:使用两个指针,分别指向头尾,然后向中间移动依次判断

int isPalindrome(string s)

{

        int i=0,j=s.size()-1;

        if (j==0)

        {

                 return 0;

        }

        while(i<j)

        {

                 if (s[i++] != s[j--])

                 {

                         return 0;

                 }

        }

        return 1;

}

 

posted @ 2016-08-06 09:01  whowhoha  阅读(124)  评论(0编辑  收藏  举报