LeetCode——Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama"
is a palindrome.
"race a car"
is not a palindrome.
Note:
Have you consider that the string might be empty?
This is a good question to ask during an interview.
For the purpose of this problem, we define empty string as valid palindrome.
原题链接:https://oj.leetcode.com/problems/valid-palindrome/
题目:给定一个字符串,检測其是否是回文串,仅仅考虑字母数字字符。
思路:过滤源字符串中的非字母数字,组成一个新串,对新串进行推断。
public static boolean isPalindrome(String s) {
if(s.isEmpty())
return true;
//过滤字母数字之外的字符
StringBuffer buf = new StringBuffer();
for(int i=0;i<s.length();i++){
if(Character.isLetterOrDigit(s.charAt(i)))
buf.append(s.charAt(i));
}
String tmp = buf.toString().toLowerCase();
for(int i=0;i<tmp.length();i++){
if(tmp.charAt(i) != tmp.charAt(tmp.length() - i - 1))
return false;
}
return true;
}
LeetCode——Valid Palindrome的更多相关文章
- [LeetCode] Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [LeetCode] Valid Palindrome II 验证回文字符串之二
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...
- [leetcode]Valid Palindrome @ Python
原题地址:https://oj.leetcode.com/problems/valid-palindrome/ 题意: Given a string, determine if it is a pal ...
- LeetCode Valid Palindrome II
原题链接在这里:https://leetcode.com/problems/valid-palindrome-ii/description/ 题目: Given a non-empty string ...
- Leetcode Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- LeetCode: Valid Palindrome [125]
[题目] Given a string, determine if it is a palindrome, considering only alphanumeric characters and i ...
- LeetCode: Valid Palindrome 解题报告
Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...
- [Leetcode] valid palindrome 验证回文
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- leetcode Valid Palindrome C++&python 题解
题目描写叙述 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...
随机推荐
- c - 字符串的反转
1,递归实现 // 递归实现字符串反转(可通过栈的调用来加深理解). char * reverse(char *c) { if(!c) return NULL; int len = strlen(c) ...
- 一个tomcat部署俩个java web项目
2.发布的时候可以发布成war包,用项目名称右键export,选择项目名称,还有发布的路径,即tomcat下的路径,参考http://zhidao.baidu.com/link?url=imOu0Uu ...
- XML样本(格式没区别,但是一个有结果 一个没结果)
xml样本01<orderlist> <order> <orderid>1</orderid> <ord ...
- HTTP,TCP,Socket
TCP/IP三次握手和HTTP过程 1.TCP连接 手机能够使用联网功能是因为手机底层实现了TCP/IP协议,可以使手机终端通过无线网络建立TCP连接.TCP协议可以对上层网络提供接口,使上层网络 ...
- Swift - 06 - 数值类型转换和类型别名
//: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...
- CentOS6.5 下 Mysql5.7主从复制
包下载http://url.cn/WrNg5S 主数据库:192.168.161.129 从数据库1:192.168.161.130 从数据库1:192.168.161.138 MySQL安装地址:/ ...
- mybatis中association的column传入多个参数值
顾名思义,association是联合查询. 在使用association中一定要注意几个问题.文笔不好,白话文描述一下. 1: <association property="fncg ...
- JQUERY1.9学习笔记 之基本过滤器(十二) 根元素选择器
根元素选择器 描述:选择文档的根节点元素.jQuery( ":root" ) 例:显示文档根节点标签名. <!DOCTYPE html><html lang=&q ...
- window.location.href问题,点击,跳转到首页
onClick="window.location.href='./';" 点击,跳转到首页. location.href=url Js中实现跳转 window.location.h ...
- 探究Android SQLite3多线程
最近做项目时在多线程读写数据库时抛出了异常,这自然是我对SQlite3有理解不到位的地方,所以事后仔细探究了一番. 关于getWriteableDataBase()和getReadableDataba ...