125. Valid Palindrome

Easy

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

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

Example 1:

Input: "A man, a plan, a canal: Panama"
Output: true

Example 2:

Input: "race a car"
Output: false
package leetcode.easy;

public class ValidPalindrome {
@org.junit.Test
public void test() {
System.out.println(isPalindrome("A man, a plan, a canal: Panama"));
System.out.println(isPalindrome("race a car"));
} public boolean isPalindrome(String s) {
s = s.trim().toLowerCase();
char[] chs = s.toCharArray();
int count = 0;
for (int i = 0; i < chs.length; i++) {
if ((chs[i] >= '0' && chs[i] <= '9') || (chs[i] >= 'a' && chs[i] <= 'z')) {
chs[count] = chs[i];
count++;
}
}
for (int i = 0; i < count / 2; i++) {
if (chs[i] != chs[count - i - 1]) {
return false;
}
}
return true;
}
}

LeetCode_125. Valid Palindrome的更多相关文章

  1. [LeetCode] Valid Palindrome 验证回文字符串

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  2. 【leetcode】Valid Palindrome

    题目简述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...

  3. Leetcode Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  4. [LintCode] Valid Palindrome 验证回文字符串

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  5. [LeetCode]题解(python):125 Valid Palindrome

    题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...

  6. 25. Valid Palindrome

    Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...

  7. [Leetcode][JAVA] Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  8. Valid Palindrome [LeetCode]

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  9. 【LeetCode OJ】Valid Palindrome

    Problem Link: http://oj.leetcode.com/problems/valid-palindrome/ The following two conditions would s ...

随机推荐

  1. Python十大经典排序算法

    现在很多的事情都可以用算法来解决,在编程上,算法有着很重要的地位,将算法用函数封装起来,使程序能更好的调用,不需要反复编写. Python十大经典算法: 一.插入排序 1.算法思想 从第二个元素开始和 ...

  2. 02_View

    1.View 1.基于类的视图 Class-based Views REST framework提供APIView是Django的View的子类 发送到View的Request请求:是REST fra ...

  3. 搭建gitlab服务

    安装依赖 sudo yum install curl policycoreutils openssh-server openssh-clients sudo systemctl enable sshd ...

  4. SQL SERVER PIVOT使用

    参照这个网址介绍 http://www.cnblogs.com/lwhkdash/archive/2012/06/26/2562979.html 一般SQL Server的函数都会识别为紫色,可是PI ...

  5. JSON.parseObject的几种用法

    https://blog.csdn.net/a18827547638/article/details/80272099 https://blog.csdn.net/a18827547638/artic ...

  6. faebdc的烦恼 莫队

    faebdc的烦恼 莫队 题面 思路 有点难想的莫队. 首先我们肯定要一个cnt[i]记录难度i出现的次数,但是我们发现每次删去一个难度后,如果那个难度的个数恰好是当前最多次数,我们就可能要更新一下答 ...

  7. 模板 - Codeforces模板

    #include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 2e5; const ...

  8. (转)mysql更改数据目录

    mysql 更改默认数据目录 http://www.cnblogs.com/chenny7/p/3642363.html 本文主要介绍在CentOS下通过yum命令安装MySQL之后,如何移动默认数据 ...

  9. class的三元表达式

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. class与computed一起应用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...