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. 数据库中聚合索引(MySQL和SQL Server区别)

    一.聚集索引和非聚集索引 聚集索引:类似字典的拼音目录.表中的数据按照聚集索引的规则来存储的.就像新华字典.整本字典是按照A-Z的顺序来排列.这也是一个表只能有一个聚集索引的原因.因为这个特点,具体索 ...

  2. mailto标签来调用邮箱客户端

    最近项目需要使用mailto标签来调用客户端,并且把邮件模板填到客户端. mailto 的用法: a标签直接调用: <a href="mailto:example@qq.com?cc= ...

  3. 安装Android Studio开发环境

    下载安装包 中文社区官网 http://android-studio.org/ 目前最新的是2.3.3版本 安装Android Studio 双击安装 等待安装包自动解压 下一步 选择安装Androi ...

  4. DNS工作流程及原理 域名、IP与DNS的关系

    转自:http://blog.csdn.net/maminyao/article/details/7390208 一.DNS服务概述 DNS是Domain Name System的缩写,即域名系统.其 ...

  5. 使用itchat进行自动微信聊天

    import itchat def we_chat(message): #enableCmdQR=2用于linux中显示二维码,hotReload=True退出程序后暂存登录状态 itchat.aut ...

  6. 怎么才能零基础彻底学会Java

    21世纪进入信息时代,信息科技给人类的生产和生活方式带来了深刻的变革,信息产业已成为推动国家经济发展的主导产业之一,Java编程语言作为含金量极高的一门IT技术,很多人希望从事这个行业,那么想学好Ja ...

  7. POJ-2065-SETI(高斯消元)

    链接: https://vjudge.net/problem/POJ-2065 题意: For some years, quite a lot of work has been put into li ...

  8. javascript权威指南第14章 表单脚本示例代码

    HTML部分 <!DOCTYPE html> <html> <head> <title></title> </head> < ...

  9. surprise库官方文档分析(二):使用预测算法

    1.使用预测算法 Surprise提供了一堆内置算法.所有算法都派生自AlgoBase基类,其中实现了一些关键方法(例如predict,fit和test).可以在prediction_algorith ...

  10. MySQL 聚集拼接

    GROUP_CONCAT()函数 示例: 假设现在有这样一个表结构: 其中`student`.`school_id`是逻辑外键 想要检索出所有学校,其中学校下的学生名需要拼接在一起,作为结果集的字段 ...