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

    public class Solution {
        public boolean isPalindrome(String s) {
            boolean isPalindrome = true;
    		s = s.toLowerCase();
    		int length = s.length();
    		int left = 0, right= length - 1;
    		while(left <= right){
    			if((s.charAt(left) < 97 || s.charAt(left) > 122) && (s.charAt(left) < 48 || s.charAt(left) > 57))
    				++left;
    			else if((s.charAt(right) < 97 || s.charAt(right) > 122) && (s.charAt(right) < 48 || s.charAt(right) > 57))
    				--right;
    			else{
    				isPalindrome &= (s.charAt(left) == s.charAt(right));
    				if(!isPalindrome)
    					break;
    				++left;
    				--right;
    			}
    		}
    		return isPalindrome;    
        }
    }
    

      

  • 相关阅读:
    快捷键 Msg消息
    类 多态(迟绑定)
    DLL发布 matlab代码发布
    获取ini内容 GetPrivateProfileString GetPrivateProfileInt
    路径操作 getModuleFileName() 等
    事件高级
    JS事件基础
    运动框架
    运动小宗
    workman安装使用
  • 原文地址:https://www.cnblogs.com/averillzheng/p/3783159.html
Copyright © 2011-2022 走看看