[Leetcode][JAVA] 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.
应该算是leetcode上最简单的题之一了吧。双指针可搞定。。
public boolean isPalindrome(String s) {
int i=0;
int j=s.length()-1;
while(i<j) {
if(!Character.isLetterOrDigit(s.charAt(i))) {
i++;
continue;
}
if(!Character.isLetterOrDigit(s.charAt(j))) {
j--;
continue;
}
if(Character.toLowerCase(s.charAt(i))!=Character.toLowerCase(s.charAt(j)))
return false;
i++;
j--;
}
return true;
}
[Leetcode][JAVA] Valid Palindrome的更多相关文章
- [LeetCode] 680. Valid Palindrome II 验证回文字符串 II
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...
- leetcode 125. Valid Palindrome ----- java
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- Java [Leetcode 125]Valid Palindrome
题目描述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...
- LeetCode 1216. Valid Palindrome III
原题链接在这里:https://leetcode.com/problems/valid-palindrome-iii/ 题目: Given a string s and an integer k, f ...
- [LeetCode] 125. Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [leetcode] 1. Valid Palindrome
leetcode的第一题,回文数判断. 原题如下: For example, "A man, a plan, a canal: Panama" is a palindrome. & ...
- 【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 ...
- LeetCode 125. Valid Palindrome
这个题目只要注意大小写问题即可解决,而且我们只关注的是字母和数值 Given a string, determine if it is a palindrome, considering only a ...
随机推荐
- jQuery图片渐变特效的简单实现
(document).ready(function() {(document).ready(function() {("div.baba").mouseleave(function ...
- 窗口 超类化 子类化 HOOK
body { font-family: Bitstream Vera Sans Mono; font-size: 11pt; line-height: 1.5; } html, body { colo ...
- 解决多网卡SNMP获取不到数据的问题
前言 前几天,公司的某个平台突然访问不了,我以为是网站挂了,于是想连接服务器查看,谁知道连服务器都连不上,然后我尝试PING,结果一直PING不通,此时我有点慌了,但我的头脑还是保持清醒的,我马上连接 ...
- hive中order by,sort by, distribute by, cluster by作用以及用法
1. order by Hive中的order by跟传统的sql语言中的order by作用是一样的,会对查询的结果做一次全局排序,所以说,只有hive的sql中制定了order by所有的 ...
- 【227】◀▶ IDL 其他常用函数
参考:Programming and Control Routines —— 编程和控制函数 01 N_ELEMENTS 表达式或者变量的元素个数. 02 DEFSYSV 定义系统变量. 03 ...
- WebForm---增删改(内置对象)
一.添加 前台代码: <body> <form id="form1" runat="server"> <h1>用户添加< ...
- time时间处理
time模块的使用 import time print(time.time()) 输出: 1476798696.6639342 #表示从1970 年 1 月 1 日 00:00:00到当前的秒数 pr ...
- 特征工程 dataframe格式
import os import copy import codecs import operator import re from math import log from pyspark.sql ...
- SQL SERVER 修改数据库名称(包括 db.mdf 名称的修改)
刚开始学习SQL SERVER 2005,弄了一个上午修改数据库名,主要是需要修改db.mdf 和db_log.ldf的名字,总算解决了.在这里记下,以后再要修改了就别忘了. 假设原来数据库名为db, ...
- phpmyadmin
下载地址:https://www.phpmyadmin.net/ 详情:http://baike.baidu.com/link?url=OIngLv0mpiYTZl_sCEmryWkHgUYqZeHr ...