zoukankan      html  css  js  c++  java
  • 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;

    }

     

  • 相关阅读:
    php Windows系统 wamp集成环境下redis的使用
    IO流文件拷贝
    IO流框架
    Map集合
    泛型
    Deque(队列)
    List接口
    Iterator接口(迭代器)
    Java中的异常详解
    Java中的正则表达式
  • 原文地址:https://www.cnblogs.com/whowhoha/p/5743285.html
Copyright © 2011-2022 走看看