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多线程实现ping多个ip

    #!/usr/bin/env python # -*- coding:utf-8 -*- import subprocess import logging import datetime import ...

  2. 函数指针,使用qsort,进行结构体排序

    #include <stdio.h> #include <stdlib.h> #define STU_NAME_LEN 16 /*学生信息*/ typedef struct s ...

  3. javascript权威指南第20章 JSON

    //20.1 语法 //JAVASCRIPT 是对JSON数据支持的. //JSON 可以申明三种类型的值 简单值("hello world") 对象({"name&qu ...

  4. oom killer 详解

    一.oom killer理解和日志分析:知识储备 oom killer日志分析,这是前篇,准备一些基础知识 带着问题看: 1.什么是oom killer 是Linux内核设计的一种机制,在内存不足的时 ...

  5. Vuex框架原理与源码分析

    Vuex是一个专为Vue服务,用于管理页面数据状态.提供统一数据操作的生态系统.它集中于MVC模式中的Model层,规定所有的数据操作必须通过 action - mutation - state ch ...

  6. F 阎小罗的Minimax (第十届山东理工大学ACM网络编程擂台赛 正式赛 )

    题解:by Mercury_Lc 阎小罗的矩阵给的n和m都不超过300,枚举一下所有情况就可以了,用前缀和来储存.数组a[x][y]代表前x行前y列的和是多少,那么枚举每一种切割的方式就可以.注意一下 ...

  7. s-w-i-p-e-r做一个-老-唬-机-抽-蒋

    <template> <div class="selfLotteryBox"> <div class="row"> < ...

  8. shiro 配置注解后无权访问不进行页面跳转异常:org.apache.shiro.authz.UnauthorizedException: Subject does not have permission

    该问题需要使用异常管理: <!-- 无权访问跳转的页面 --> <bean class="org.springframework.web.servlet.handler.S ...

  9. codeforces#1257 F. Make Them Similar ( 经典中间相遇问题 )

    题目链接: http://codeforces.com/contest/1257/problem/F 题意: 给出$n$个30位整数 找到一个数,让它与这$n$个数分别异或,得到的$n$个数二进制1的 ...

  10. 小程序 之自定义tabbar上边框颜色

    一.设置borderStyle 二.设置page样式 page::after{ content: ''; position: fixed; left: 0; bottom: 0; width: 100 ...