当前位置:网站首页>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
边栏推荐
- MongoDB的原理、基本使用、集群和分片集群
- [buuctf.reverse] 121-125
- Ruiji takeout project (II)
- ShardingSphere-Proxy 5.0 分库分表(一)
- STM32 receives data by using idle interrupt of serial port
- Cubemx stm32f105rb USB flash drive reading and writing detailed tutorial
- CYCA 2022少儿形体礼仪初级师资班 深圳总部站圆满结束
- What functions should smart agriculture applet system design have
- 在指南针上面开股票账户好不好,安不安全?
- Mongodb's principle, basic use, clustering and partitioned clustering
猜你喜欢
Redis (I) principle and basic use
x86电脑上下载debian的arm64的包
How to build a wechat applet? How to open an applet?
How do wechat applets make their own programs? How to make small programs on wechat?
How do wechat sell small commodity programs do? How to open wechat apps to sell things?
MongoDB的原理、基本使用、集群和分片集群
8、智慧交通项目(1)
Modbus协议与SerialPort端口读写
Notes on writing questions in C language -- monkeys eat peaches
Basic use and cluster construction of consult
随机推荐
Jetpack compose layout (II) - material components and layout
CYCA少儿形体礼仪 乐清市培训成果考核圆满落幕
可穿戴设备或将会泄露个人隐私
What should be paid attention to in PMP examination?
Free platform for wechat applet making, steps for wechat applet making
[MySQL learning notes 22] index
瑞萨RA系列-开发环境搭建
[Ruby on rails full stack course] course directory
How to make a self-service order wechat applet? How to do the wechat order applet? visual editing
Mongodb's principle, basic use, clustering and partitioned clustering
依赖属性、依赖附加属性以及类型转换
如何自制一个安装程序,将程序打包生成安装程序的办法
51 SCM time stamp correlation function
ShardingSphere-Proxy 4.1 分庫分錶
Is it safe to open a stock account on the compass?
Processing picture class library
Download the arm64 package of Debian on X86 computer
Linked list delete nodes in the linked list
Pytorch_Geometric(PyG)使用DataLoader报错RuntimeError: Sizes of tensors must match except in dimension 0.
Huipay international permet au commerce électronique transfrontalier de devenir une plate - forme de paiement transfrontalière conforme!