zoukankan      html  css  js  c++  java
  • Valid Palindrome

    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.

    Note:
    Have you consider that the string might be empty? This is a good question to ask during an interview.

    For the purpose of this problem, we define empty string as valid palindrome.

     1 public class Solution {
     2     public static boolean isPalindrome(String s)
     3     {
     4         char[]ch=s.toLowerCase().toCharArray();
     5         int i=0,j=ch.length-1;
     6         while(i<j)
     7         {
     8             while(i<ch.length&&!(ch[i]>='a'&&ch[i]<='z'||ch[i]>='0'&&ch[i]<='9'))
     9                 i++;
    10             while(j>=0&&!(ch[j]>='a'&&ch[j]<='z'||ch[j]>='0'&&ch[j]<='9'))
    11                 j--;
    12             if(i>ch.length-1||j<0)
    13                 return true;
    14             if(ch[i]!=ch[j])
    15                 return false;
    16             i++;
    17             j--;
    18             
    19         }
    20         return true;
    21     }
    22     public static void main(String args[])
    23     {
    24         boolean b=isPalindrome(",.");
    25         System.out.println(b);
    26     }
    27 }
  • 相关阅读:
    mongodb 配置单实例与双实例
    redis 集群 搭建
    memcached 搭建
    公网yum 源地址
    jdk 安装
    activemq 搭建--集群
    zookeeper 安装
    activemq 安装-单点
    rabbitmq 集群
    python——网络编程
  • 原文地址:https://www.cnblogs.com/qq1029579233/p/4404991.html
Copyright © 2011-2022 走看看