当前位置:网站首页>字符串 实现 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
}
}
思路:
指针向右移,对比
边栏推荐
- Voiceprint Technology (V): voiceprint segmentation and clustering technology
- Remove the mosaic, there's a way, attached with the running tutorial
- PHP obtains the IP address, and the apache2 server runs without error
- Is it safe to open a stock account through the account opening QR code of the account manager?
- CYCA 2022少儿形体礼仪初级师资班 深圳总部站圆满结束
- Mysql 源码阅读(二)登录连接调试
- Pytorch_Geometric(PyG)使用DataLoader报错RuntimeError: Sizes of tensors must match except in dimension 0.
- clang frontend command failed with exit code 250
- How to download the school logo, school name and corporate logo on a transparent background without matting
- 2台三菱PLC走BCNetTCP协议,能否实现网口无线通讯?
猜你喜欢

How to delete a blank page that cannot be deleted in word

Prediction of pumpkin price based on BP neural network

SQL advanced

Is it harder to find a job in 2020? Do a good job in these four aspects and find a good job with high salary

Register the jar package as a service to realize automatic startup after startup
![[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

Title B of the certification cup of the pistar cluster in the Ibagu catalog

2022 postgraduate entrance examination experience post -- Alibaba Business School of Hangzhou Normal University -- management science and Engineering (including the recommendation of books and course

x86电脑上下载debian的arm64的包

Etcd tutorial - Chapter 4 etcd cluster security configuration
随机推荐
Neat Syntax Design of an ETL Language (Part 2)
Fluent: target support file /pods runner / pods runner frameworks Sh: permission denied - stack overflow
请问在手机上开户股票,还是去证券公司开户安全?
测试开发工程师
Work of the 15th week
从海量手机号中匹配某一个手机号
[competition - Rural Revitalization] experience sharing of Zhejiang Rural Revitalization creative competition
使用EVO
CYCA 2022少儿形体礼仪初级师资班 深圳总部站圆满结束
Shuttle JSON, list, map inter transfer
manhattan_ Slam environment configuration
Huipay international permet au commerce électronique transfrontalier de devenir une plate - forme de paiement transfrontalière conforme!
Set the location permission in the shutter to "always allow"
Register the jar package as a service to realize automatic startup after startup
STM32 receives data by using idle interrupt of serial port
Is it harder to find a job in 2020? Do a good job in these four aspects and find a good job with high salary
2022 meisai question a idea sharing
Fcpx quickly add subtitles | Final Cut Pro import fcpxml subtitle file does not match the video time? I got it in code
Is it safe to open a stock account through the account opening QR code of the account manager?
How to "transform" small and micro businesses (I)?