博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[leetcode]Valid Palindrome
阅读量:4545 次
发布时间:2019-06-08

本文共 1058 字,大约阅读时间需要 3 分钟。

问题描写叙述:

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.

代码:

import java.util.Vector;public class Valid_Palindrome {	public boolean isPalindrome(String s) {		s = s.toLowerCase();		Vector
vector = new Vector
(); for(int i = 0; i< s.length(); i++){ Character ch = s.charAt(i); if((ch >='a' && ch <='z' )||(ch >='0' && ch <='9')) vector.add(ch); } if(vector.size() == 0) return true; int size = vector.size(); for(int i=0; i< size/2; i++){ if(vector.get(i) != vector.get(size-1-i)) return false; } return true; }}

转载于:https://www.cnblogs.com/zfyouxi/p/5271220.html

你可能感兴趣的文章
Mac显示器不亮
查看>>
luogu P2312 解方程
查看>>
Cordova开发速记
查看>>
Chrome开发工具
查看>>
MySQL 的 RowNum 实现
查看>>
网络工程师应该掌握的44个路由器问题
查看>>
windows 控制台下运行cl命令
查看>>
(七十八)使用第三方框架INTULocationManager实现定位
查看>>
LeetCode问题:搜索插入位置
查看>>
JVM基础学习之基本概念、可见性与同步
查看>>
UML入门
查看>>
CodeForces - 524F And Yet Another Bracket Sequence
查看>>
python学习笔记-day10-2【多进程,多线程】
查看>>
Atitit 图像处理 平滑 也称 模糊, 归一化块滤波、高斯滤波、中值滤波、双边滤波)...
查看>>
Android Camera——拍照(转自http://vaero.blog.51cto.com/4350852/779942)
查看>>
Java Web项目移植
查看>>
11月的第一天
查看>>
2011简单总结
查看>>
android的Environment类,记录一下
查看>>
工作流Activiti5流程变量 任务变量 setVariables 跟 setVariablesLocal区别
查看>>