当前位置:网站首页>20 -- validate palindrome string
20 -- validate palindrome string
2022-07-24 17:27:00 【JH_ Cao】
1. subject
Given a string , Verify that it is a palindrome string , Consider only alphabetic and numeric characters , The case of letters can be ignored .
explain : In this question , We define an empty string as a valid palindrome string .
Example 1:
Input : “A man, a plan, a canal: Panama”
Output : true
explain :“amanaplanacanalpanama” It's a palindrome string
Example 2:
Input : “race a car”
Output : false
explain :“raceacar” It's not a palindrome string
- Pay attention to the examination — Alphanumeric characters
2. Ideas
Double pointer
func isPalindrome(_ s: String) -> Bool {
let nums: [String.Element] = ["0","1","2","3","4","5","6","7","8","9"]
// Here is higher-order grammar
let tempArr: [String.Element] = Array(s.lowercased()).reduce(into: []) { partialResult, char in
if char >= "a" && char <= "z" || nums.contains(char) {
partialResult.append(char)
}
}
// print(tempArr)
var left = 0, right = tempArr.count - 1
while left <= right {
if tempArr[left] == tempArr[right] {
left += 1
right -= 1
} else {
return false
}
}
return true
}
边栏推荐
- GDB online debugging of work notes
- NPM install reported -4058 error
- What is fuzzy theory, foundation and process
- Safety: how to provide more protection for pedestrians
- Hcip fourth day notes
- 2022 Asia International Internet of things exhibition
- Check the actual data growth of the database
- [how to optimize her] teach you how to locate unreasonable SQL? And optimize her~~~
- [wechat official account H5] authorization
- Analog electricity - what is the resistance?
猜你喜欢

One article of quantitative framework backtrader: understand indicator indicators

Canvas 从入门到劝朋友放弃(图解版)

Kernel development
ShardingSphere数据库读写分离

Internet Download Manager配置

QT embed Notepad under win10

opencv自带颜色操作

Number theory division block explanation example: 2021 Shaanxi Race C

键盘输入操作

一个实际使用SwiftUI 4.0中ViewThatFits自适应视图的例子
随机推荐
Separation and merging of channels
A problem of MySQL database
quick get start
快速入门
Analyze the capabilities and scenarios of Apache pulsar, a cloud native message flow system
2022年最新浙江建筑安全员模拟题库及答案
DHCP relay of HCNP Routing & Switching
CDN(Content Delivery Network)内容分发网络从入门到与实战
Today, I met a 38K from Tencent, which let me see the ceiling of the foundation
UFW port forwarding
PAT甲级——拼写正确
Still using xshell? You are out, recommend a more modern terminal connection tool!
Kernel development
Is Shenwan Hongyuan securities' low commission account reliable, reliable and safe
Rare earth Developer Conference | Apache pulsar committee Liu Dezhi shares the way of cloud native technology transformation
Ipaylinks, a cross-border payment integration service, won the 3A Asia Award of treasury
什么是模糊理论,基础,流程
Getaverse,走向Web3的远方桥梁
Iftnews | Christie's launched its venture capital department, aiming at Web3 and metauniverse industries
Method of querying comma separated strings in a field by MySQL