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 ...
随机推荐
- asp.net基础概念总结
1 什么是asp.net?asp.net是一种编程语言吗? asp.net是Microsoft公司推出的新一代建立动态web应用程序的开发平台,是一种建立动态web应用程序的新技术. 不是,asp. ...
- Oracle order by case when 多条件排序
ORACLE sql 排序 根据两个条件排序,根据id号由小到大排序,同时country字段是北京的排最前面前面,其次上海,..大连,最后是其他城市,怎么写? 写法如下:select * from p ...
- 自由创造属于你的H5内容
在这里,你可以自由创造属于你的H5内容 mark下 http://www.ih5.cn/
- 使用HTML+CSS,jQuery编写的简易计算器
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- jquery validate 配合ligerui使用
这样当单击登录按钮时右边会弹出一个小框框,同时显示jquery扩展的下面那段代码错误内容,当添加内容正确后小框框消失,lable换成error也行 $("#form1").vali ...
- Apache Commons DbUtils Problem
- HTML5 QQ登录背景动态图片
预览效果如图所示: 代码如下: <!DOCTYPE html> <head> <meta http-equiv="Content-Type" cont ...
- jQuery操作cookie
验证jquery的cookie插件时才知道原先文件一直在桌面上放着执行发现没有效果,文件必须放在web服务器下面执行才会生效,晕菜! $.cookie(name,value,{expires: 7,p ...
- PHP文件系统概述
>> 本文固定链接: http://php.ncong.com/php_course/file/wenjianxitong.html >> 转载请注明: 恩聪php 2014年 ...
- 三种php连接access数据库方法
种是利用php的pdo,一种是odbc,com接口来与access数据库连接.利用pdo与access数据库连接 $path ="f:fontwww.jb51.netspiderresult ...