当前位置:网站首页>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
}
边栏推荐
- Internet Download Manager配置
- Image information is displayed by browser: data:image/png; Base64, + image content
- Wrote a few small pieces of code, broke the system, and was blasted by the boss
- opencv自带颜色操作
- Programming language exercises (I)
- TCP协议调试工具TcpEngine V1.3.0使用教程
- What is fuzzy theory, foundation and process
- Bring 120W goods in 15 seconds. You can also shoot such a popular video
- Is it safe for Mr. qiniu to open a securities account? Can I drive it?
- socat 端口转发
猜你喜欢

快速入门

opencv自带颜色操作

Cann training camp learns the animation stylization and AOE ATC tuning of the second season of 2022 model series

调整图像亮度的滚动条演示实验

Programming language exercises (I)

Xxx.pro learning in QT

别再到处乱放配置文件了!试试我司使用 7 年的这套解决方案,稳的一秕

Qsqldatabase: solution of qmmysql driver not loaded
![[how to optimize her] teach you how to locate unreasonable SQL? And optimize her~~~](/img/10/996d594a53d9a34a36079fed829f27.png)
[how to optimize her] teach you how to locate unreasonable SQL? And optimize her~~~

Three.js (7): local texture refresh
随机推荐
Axi protocol (3): handshake mechanism and implementation details of Axi architecture
ShardingSphere数据库读写分离
[GNN report] Tencent AI Lab Xu TingYang: graph generation model and its application in molecular generation
量化框架backtrader之一文读懂Indicator指标
CDN(Content Delivery Network)内容分发网络从入门到与实战
Portfwd port forwarding
一个实际使用SwiftUI 4.0中ViewThatFits自适应视图的例子
Method of querying comma separated strings in a field by MySQL
别再到处乱放配置文件了!试试我司使用 7 年的这套解决方案,稳的一秕
The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced
PAT甲级——签到与签出
Natbypass port forwarding
Explain Apache Hudi schema evolution in detail
Number theory division block explanation example: 2021 Shaanxi Race C
Atcoder beginer 202 e - count descendants (heuristic merge on heavy chain split tree for offline query)
2022-07-21 Daily: Wu Enda wrote: how to establish projects suitable for AI career
Code random notes_ Linked list_ 707 design linked list
socat 端口转发
[matlab]: basic knowledge learning
Safety: how to provide more protection for pedestrians