首页 > 其他 > 详细

leetcode4 Valid Palindrome回文数

时间:2016-08-06 09:57:35      阅读:295      评论:0      收藏:0      [点我收藏+]

  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;

}

 

leetcode4 Valid Palindrome回文数

原文:http://www.cnblogs.com/whowhoha/p/5743285.html

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