当前位置:网站首页>String implementation strstr()
String implementation strstr()
2022-06-25 10:06:00 【Morris_】
LC Realization strStr()
swift The code is as follows :
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
print(strStr("hello", "ll"))
print(strStr("aaaaa", "bba"))
}
func strStr(_ haystack: String, _ needle: String) -> Int {
if needle.isEmpty {
return 0
}
let array1 = Array(haystack)
let array2 = Array(needle)
var i = 0
while (i + array2.count) <= array1.count {
let temp: Array = Array(array1[i...i + array2.count - 1])
if temp == array2 {
return i
}
i += 1
}
return -1
}
}
Ideas :
Move the pointer to the right , contrast 
边栏推荐
- Huipay international permet au commerce électronique transfrontalier de devenir une plate - forme de paiement transfrontalière conforme!
- Is GF Securities reliable? Is it legal? Is it safe to open a stock account?
- Solution to the problem of repeated startup of esp8266
- ShardingSphere-Proxy 4.1 分庫分錶
- Shuttle JSON, list, map inter transfer
- Processing picture class library
- 可穿戴设备或将会泄露个人隐私
- js工具函数,自己封装一个节流函数
- puzzle(019.2)六边锁
- The gradle configuration supports the upgrade of 64 bit architecture of Xiaomi, oppo, vivo and other app stores
猜你喜欢

CYCA少儿形体礼仪 乐清市培训成果考核圆满落幕

puzzle(019.2)六边锁

How to make a self-service order wechat applet? How to do the wechat order applet? visual editing

ShardingSphere-Proxy 5.0 分库分表(一)

MongoDB的原理、基本使用、集群和分片集群

匯付國際為跨境電商賦能:做合規的跨境支付平臺!

Basic use and cluster construction of consult

Shardingsphere proxy 4.1 Sous - base de données sous - table

Mengyou Technology: tiktok live broadcast with goods elements hot topics retention skills shaping image highlight selling points

NetCore性能排查
随机推荐
Jetpack compose layout (III) - custom layout
Grabcut image segmentation in opencv
Is it safe to open a stock account on the compass?
Etcd教程 — 第四章 Etcd集群安全配置
WebApi性能优化
MongoDB的原理、基本使用、集群和分片集群
Redis (II) distributed locks and redis cluster construction
How to make a self-service order wechat applet? How to do the wechat order applet? visual editing
Encoding format for x86
Simple waterfall effect
[MySQL learning notes 20] MySQL architecture
Cocopod error failed: undefined method `map 'for nil:nilclass
Redis(一)原理与基本使用
CyCa children's physical etiquette Yueqing City training results assessment successfully concluded
ScheduleMaster分布式任务调度中心基本使用和原理
Processing picture class library
How much does a small program cost? How much does a small program cost? It's clear at a glance
Redis (I) principle and basic use
Pytorch_ Geometric (pyg) uses dataloader to report an error runtimeerror: sizes of tenants must match except in dimension 0
Nano data World Cup data interface, CSL data, sports data score, world cup schedule API, real-time data interface of football match