【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.
解题思路:
class Solution:
# @param s, a string
# @return a boolean
def isPalindrome(self, s):
if s == '':
return True
s = s.strip().lower()
t = ''
for i in s:
if (i <= '9' and i >= '0') or (i <= 'z' and i >= 'a'):
t += i
l = len(t)
for i in range(l/2):
if t[i] != t[l-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(右回文)
[ 问题: ] Given a string, determine if it is a palindrome, considering only alphanumeric characters an ...
- 【leetcode】Valid Palindrome II
很久没有做题了,今天写个简单难度的练练手感. Given a non-empty string s, you may delete at most one character. Judge wheth ...
- 【Leetcode】【Easy】Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 【LeetCode】9. Palindrome Number (2 solutions)
Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. click t ...
- 【leetcode】1278. Palindrome Partitioning III
题目如下: You are given a string s containing lowercase letters and an integer k. You need to : First, c ...
- 【LeetCode】336. Palindrome Pairs 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 HashTable 相似题目 参考资料 日期 题目地 ...
- 【LeetCode】9. Palindrome Number 回文数
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ...
- 【LeetCode】234. Palindrome Linked List 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
随机推荐
- nginx安装与配置
一.在线安装 ubuntu 安装 sudo apt-get install nginx 安装后文件结构为: 配置文件:/etc/nginx ,并且每台虚拟主机已经安排在 /etc/nginx/site ...
- c++ 在windows下获取时间和计算时间差的几种方法总结
http://blog.csdn.net/caimagic/article/details/50696609 我用的是GetTickCount(), 获取到的是毫秒.
- 【学习笔记】C语言之词法规则
一.字符 标准并没有规定C环境必须使用特定的字符集,但是它规定了字符集必须包含英语所有的大小写字母,数字0到9,以及下面的字符: ! # % ^ & * ( ) _ – + = / . ? ...
- Android Studio开发Android应用如何签名
1.使用jdk自带的工具生成keystore 使用cmd命令行进入到jdk的bin目录(比如:C:\Program Files\Java\jdk1.7.0_01\bin) 运行如下命令: C:\Pro ...
- hashMap 深入理解
1.java 的hashMap 是通过 链地址 法来解决 hash冲突的 2.初始时是一个empty table, 第一次添加数据时检查到时空数组就会 生成指定容量的数组,也就是 在第一次使用时才初始 ...
- Eclipse常用快捷键汇总
经常使用eclipse进行开发,不掌握快捷键步行啊,在此整理了一些快捷键,大家要灵活运用啊... (注:红色标出来的是经常使用到的快捷键,磨刀不误砍柴工啊...) Ctrl+1 快速修复(最经典的快捷 ...
- nmq消息队列解析
消息中间件NMQ 1.What is nmq? nmq = new message queue; 一个通用消息队列系统 为在线服务设计 什么是消息队列?问什么需要?有哪些功能? 消息队列的本质:1.多 ...
- ASP.NET上实现
ASP.NET上实现 fengzhuang.cs: using System;using System.Collections.Generic;using System.Linq;using Syst ...
- svn post-commit 同步
@echo on SET REPOS=%1 SET USER=%2 SET SVN="D:\Program Files\VisualSVN Server\bin\svn.exe" ...
- 打不死的redis集群
导读 最近遇到部分系统因为redis服务挂掉,导致部分服务不可用.所以希望搭建一个redis集群镜像,把原先散落各处的redis服务器统一管理起来,并且保障高可用和故障自动迁移. 最近遇到部分系统因为 ...