当前位置:网站首页>字符串 实现 strStr()
字符串 实现 strStr()
2022-06-25 09:37:00 【Morris_】
LC 实现 strStr()
swift 代码如下:
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
}
}
思路:
指针向右移,对比
边栏推荐
- Is it safe to open an account online? Who can I ask?
- How much money have I made by sticking to fixed investment for 3 years?
- CyCa 2022 children's physical etiquette primary teacher class Shenzhen headquarters station successfully concluded
- What are the PMP scores?
- Remove the mosaic, there's a way, attached with the running tutorial
- [shared farm] smart agriculture applet, customized development and secondary development of Kaiyuan source code, which is more appropriate?
- Remittance international empowers cross-border e-commerce: to be a compliant cross-border payment platform!
- Force buckle -104 Maximum depth of binary tree
- MySQL创建给出语句
- PMP考试多少分算通过?
猜你喜欢
![[zufe expense reimbursement] zhecai invoice reimbursement specification (taking Xinmiao reimbursement as an example), which can be passed in one trip at most](/img/28/c5c6b6d03b459745dc3735f8b39ea9.jpg)
[zufe expense reimbursement] zhecai invoice reimbursement specification (taking Xinmiao reimbursement as an example), which can be passed in one trip at most

Vscode attempted to write the procedure to a pipeline that does not exist

How to "transform" small and micro businesses (II)?
![[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate](/img/75/a06e20b4394579cbd9f6d3a075907a.jpg)
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate

Register the jar package as a service to realize automatic startup after startup

Wallys/MULTI-FUNCTION IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL

Rxjs TakeUntil 操作符的学习笔记

瑞萨RA系列-开发环境搭建

Reasons for Meiye to choose membership system

Wallys/MULTI-FUNCTION IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL
随机推荐
Register the jar package as a service to realize automatic startup after startup
[shared farm] smart agriculture applet, customized development and secondary development of Kaiyuan source code, which is more appropriate?
华泰证券在上面开户安全吗?靠谱吗?
Is it safe to open an account on the compass?
在指南针上面开户好不好,安不安全?
SQL advanced
MySQL创建给出语句
Is it safe to open an account in a mobile phone or a securities company?
Unique Wulin, architecture selection manual (including PDF)
js工具函数,自己封装一个节流函数
Use evo
manhattan_ Slam environment configuration
Title B of the certification cup of the pistar cluster in the Ibagu catalog
Arduino bootloader burning summary
Voiceprint Technology (I): the past and present life of voiceprint Technology
手机办理长城证券开户靠谱安全吗?
Study on correlation of pumpkin price and design of price prediction model based on BP neural network
Is GF Securities reliable? Is it legal? Is it safe to open a stock account?
Processing picture class library
Creating a binary tree (binary linked list) from a generalized table