LeetCode_125. Valid Palindrome
125. Valid Palindrome
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的更多相关文章
- [LeetCode] Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 【leetcode】Valid Palindrome
题目简述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...
- Leetcode Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [LintCode] Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [LeetCode]题解(python):125 Valid Palindrome
题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...
- 25. Valid Palindrome
Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...
- [Leetcode][JAVA] Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- Valid Palindrome [LeetCode]
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 【LeetCode OJ】Valid Palindrome
Problem Link: http://oj.leetcode.com/problems/valid-palindrome/ The following two conditions would s ...
随机推荐
- grep redis-cli command
https://www.reddit.com/r/redis/comments/atfvqy/how_to_grep_from_monitor_command/ _------------------ ...
- UML之关系
学习UML我们首先要掌握他们的关系,UML关系可以分为四类,主要有关联.依赖.泛化和实现. 下面我们就一一来详细说明这几种关系. 关联 表示两个类或类与接口之间强烈的依赖关系,关联用直线表示.当然我们 ...
- Robot Framework--完整的接口测试用例
*** Settings *** Library Collections Library json Library requests Library RequestsLibrary Library H ...
- Java实习生面试题分享
1.Java有那些基本数据类型,String是不是基本数据类型,他们有何区别. Java语言提供了八种基本类型: 六种数字类型(四个整数型,两个浮点型) 字节型byte 8位 短整型short 16位 ...
- 分页器,序列化组件,bulk_create,choices字段
分页器 <!--前端--> {% for book in page_queryset %} <p>{{ book.title }}</p> {% endfor %} ...
- 如何的keil试试调试中,看逻辑分析仪Logic viwer
在调试过程中,可以使用keil自带的逻辑分析仪查看变量的试试信息,减少串口输出,提高部分cpu的效率,可以添加以下信息: 1.gpio引脚 2.全局变量 全局静态变量.局部变量是不行的. 然后,添加变 ...
- Mina整体体系结构分析
mina在应用程序中处于什么样的地位? mina屏蔽了一些网络通信细节对socket进行封装,并且基于NIO非阻塞框架,可以帮助我们快速开发网络通信,常常用于用户游戏开发,中间件等服务端应用程序.
- umediter实现粘贴word图片
图片的复制无非有两种方法,一种是图片直接上传到服务器,另外一种转换成二进制流的base64码目前限chrome浏览器使用首先以um-editor的二进制流保存为例:打开umeditor.js,找到UM ...
- luogu 3702 [SDOI2017]序列计数 矩阵乘法+容斥
现在看来这道题真的不难啊~ 正着求不好求,那就反着求:答案=总-全不是质数 这里有一个细节要特判:1不是质数,所以在算全不是质数的时候要特判1 code: #include <bits/stdc ...
- 10分钟教你用eclipse上传代码到GitHub
关注我们的公众号哦!获取更多精彩消息! 好久没有更新了,这两天小编在整理以前的代码,上传到GitHub做备份. 加上现在GitHub的私有仓库不是免费了嘛,所以今天顺便给大家讲讲怎么用eclipse上 ...