[LeetCode]题解(python):125 Valid Palindrome
题目来源
https://leetcode.com/problems/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.
题意分析
Input: a string
Output: whether the string is valid palindrome
Conditions: 判断是否是回文串,忽略非数字和非字母的字符
题目思路
采用isalnum来判断是否为字母或数字,然后将字符转为小写(题目认为大小写是一样的),然后简单判断是否是回文。
AC代码(Python)
class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
c = []
for i in s:
if i.isalnum():
c.append(i.lower())
for i in range(len(c)/2):
if c[i] != c[len(c)-1-i]:
return False
return True
[LeetCode]题解(python):125 Valid Palindrome的更多相关文章
- 125. Valid Palindrome【easy】
125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphan ...
- 【LeetCode】125. Valid Palindrome 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 列表生成式 正则表达式 双指针 日期 题目地址:https:/ ...
- [LeetCode] 125. Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 【一天一道LeetCode】#125. Valid Palindrome
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- leetcode 125. Valid Palindrome ----- java
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 ...
- Java [Leetcode 125]Valid Palindrome
题目描述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...
- 【LeetCode】125. Valid Palindrome
题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...
- [leetcode]125. Valid Palindrome判断回文串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
随机推荐
- Fetch from Upstream 变灰失效
Team——>Remote——>Configure Fetch from Upstream… Team——>Remote——>Configure Push to Upstre ...
- ACM Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- ACM +-字符串
+-字符串 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 Shiva得到了两个只有加号和减号的字符串,字串长度相同.Shiva一次可以把一个加号和它相邻的减号交换. ...
- ACM: 畅通工程-并查集-解题报告
畅通工程 Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 某省调查城镇交通状况 ...
- 洛谷 P1031 均分纸牌 Label:续命模拟QAQ
题目描述 有 N 堆纸牌,编号分别为 1,2,…, N.每堆上有若干张,但纸牌总数必为 N 的倍数.可以在任一堆上取若于张纸牌,然后移动. 移牌规则为:在编号为 1 堆上取的纸牌,只能移到编号为 2 ...
- Some useful links
Integrating the FlyCapture SDK for use with OpenCV CStereoGrabber_Bumblebee.h OpenCV with PGR Flycap ...
- MySql_设置编码
1.查看mysql编码(默认latin1) show variables like 'collation_%'; +--------------------------+--------------- ...
- Hadoop.2.x_WebUV示例
一.网站基本指标(即针对于网站用户行为而产生的日志中进行统计分析) 1. PV:网页浏览量(Page View页面浏览次数,只要进入该网页就产生一条记录,不限IP,统计点每天(较多)/每周/每月/.. ...
- Linux_sudo权限
一.sudo权限(只能由管理员操作) 1. 操作对象 --> 命令(命令也是文件) 2. 命令存放路径/sbin与/bin --> 只由root管理员用户操作 3. 实际工作中,是不允许你 ...
- scala case class
在我们详细介绍Scala的Case class和模式匹配之前,我们可以通过一个简单的例子来说明一些基本概念.我们设计一个函数库,这个函数库可以用来计算算术表达式,为简单起见,我们设计的算术表达式只侧重 ...