当前位置:网站首页>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 
边栏推荐
- 广发证券靠谱吗?是否合法?开股票账户安全吗?
- Vscode attempted to write the procedure to a pipeline that does not exist
- [MySQL learning notes 22] index
- CyCa 2022 children's physical etiquette primary teacher class Shenzhen headquarters station successfully concluded
- SQL to object thinking vs SQL of object thinking
- [Ruby on rails full stack course] course directory
- What are the PMP scores?
- 从海量手机号中匹配某一个手机号
- Wearable devices may reveal personal privacy
- Opencv中的GrabCut图像分割
猜你喜欢

Get started quickly with jetpack compose Technology

Webapi performance optimization

How do wechat applets make their own programs? How to make small programs on wechat?

2台三菱PLC走BCNetTCP协议,能否实现网口无线通讯?

Chitubox micromake l3+ slicing software configuration correspondence

Redis(二)分布式锁与Redis集群搭建

The gradle configuration supports the upgrade of 64 bit architecture of Xiaomi, oppo, vivo and other app stores

Reasons for Meiye to choose membership system

Wechat official account can reply messages normally, but it still prompts that the service provided by the official account has failed. Please try again later

Ruiji takeout project (II)
随机推荐
Shuttle JSON, list, map inter transfer
广发证券靠谱吗?是否合法?开股票账户安全吗?
CyCa children's physical etiquette Yueqing City training results assessment successfully concluded
可穿戴设备或将会泄露个人隐私
x86电脑上下载debian的arm64的包
Grabcut image segmentation in opencv
瑞吉外卖项目(二)
Etcd教程 — 第四章 Etcd集群安全配置
测试开发工程师
[buuctf.reverse] 121-125
Can two Mitsubishi PLC adopt bcnettcp protocol to realize wireless communication of network interface?
CYCA少儿形体礼仪 乐清市培训成果考核圆满落幕
Redis (I) principle and basic use
汇付国际为跨境电商赋能:做合规的跨境支付平台!
Reasons for Meiye to choose membership system
Unique Wulin, architecture selection manual (including PDF)
Methodchannel of flutter
瑞萨RA系列-开发环境搭建
How do dating applets make millions a year? What is the profit model?
Cubemx stm32f105rb USB flash drive reading and writing detailed tutorial