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算法与数据结构-常用查找算法一(37)

    一.什么是查找 查找(Searching)就是根据给定的某个值,在查找表中确定一个其关键字等于给定值的数据元素(或记录). 查找表(Search Table):由同一类型的数据元素(或记录)构成的集合 ...

  2. 《3+1团队》第七次作业:团队项目设计完善&编码

    项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 3+1团队 团队博客地址 https://home.cnblogs.com/u/3-1group ...

  3. Mysql-Percona mysql5.7简单安装

    Mysql-Percona mysql5.7简单安装 一.什么是Percona 单从mysql的角度来讲,可以把Percona理解为mysql的一个分支,因为mysql的源码是开源的,Percona就 ...

  4. 2.4 vue配置(下)

  5. Redis的下载、安装及启动

    一.下载Redis 1. redis 的下载路径 https://pan.baidu.com/s/1tdMzOlcTlFC7Z3a3I_59hQ 提取码:5tgy 二.安装Redis cd到当前解压目 ...

  6. [cogs] 传染病控制

    http://cogs.pro:8080/cogs/problem/problem.php?pid=107 去年6月份的代码了,又长又臭又WA 暴力贪心模拟 水水50 #include<iost ...

  7. 2018-2019 ACM-ICPC, Asia Dhaka Regional Contest

    目录 Contest Info Solutions B. Counting Inversion C. Divisors of the Divisors of An Integer E. Helping ...

  8. 贾扬清牛人(zz)

    贾扬清加入阿里巴巴后,能否诞生出他的第三个世界级杰作? 文 / 华商韬略 张凌云  本文转载,著作权归原作者所有   贾扬清加入阿里巴巴后,能否诞生出他的第三个世界级杰作? 2017年1月11日,美国 ...

  9. 微信小程序环境下将文件上传到 OSS

    步骤 1: 配置 Bucket 跨域 客户端进行表单直传到 OSS 时,会从浏览器向 OSS 发送带有 Origin 的请求消息.OSS 对带有 Origin 头的请求消息会进行跨域规则(CORS)的 ...

  10. mac 启动mysql

    sudo /usr/local/mysql/support-files/mysql.server stop sudo /usr/local/mysql/support-files/mysql.serv ...