大家好,我是毛毛。ヾ(´∀ ˋ)ノ
废话不多说开始今天的解题Day~
Given a string s
, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.
Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.
1 <= s.length <= 2 * 10^5
s
consists only of printable ASCII characters.首先先简单的翻译一下题目
给一个字串,要把除了英文字母以外的符号和空白都删掉,然後看这个字串是不是对称的(忽略大小写)。
作法大致上是这样
class Solution:
def isPalindrome(self, s: str) -> bool:
s = s.strip()
for character in ['\\', '`', '*', '_', '{',\
'}', '[', ']', '(', ')', \
'>', '#', '+', '-', '.',
'!', '$', '\'', ' ', ',',\
':', '%', '^', '<', '&',\
'=', '?', '{', '}', '|',\
'/', '~', '@', '\"', ';']:
if character in s:
s = s.replace(character,"")
s = s.lower()
# print(s)
low = 0
high = len(s)-1
while(low<=high):
if s[low] != s[high]:
return False
low += 1
high -= 1
return True
Python
大家明天见
<<: Day29 Lab 2 - Object storage数据压缩
用html2canvas转成canvas,再下载 载入js,js会把div里的东西,转换成canva...
absolute + top/left + tranform 利用top/left将子元素的左上角对...
这在好几章以前有提过,我希望能透过增加不同的分页使每个练习分门别类,当然,要完成的作品也是。 但拜读...
其实订阅订单跟定期定额作法非常相似, 这边会额外拉出来讲是因为个人对於他们两兄弟有不同定义, 文章是...
在进入机器学习之前,想先大家深入了解一些 python 的进阶操作。接下来的操作会有点抽象,请好好品...