当前位置:网站首页>Implement strstr() II
Implement strstr() II
2022-07-02 06:43:00 【Sand is sand】
Given a haystack String and a needle character string , stay haystack Find in string needle The first place the string appears ( from 0 Start ). If it doesn't exist , Then return to -1.
Example 1:
Input : haystack= "hello", needle = "ll"
Output : 2
Example 2:
Input : haystack= "aaaaa", needle = "bba"
Output : -1
explain :
When needle When it's an empty string , What value should we return ? This is a good question in an interview .
For this question , When needle When it's an empty string, we should return 0 . This is related to C Linguistic strstr() as well as Java Of indexOf() The definition matches .
resolvent :
Algorithmic thought :
primary strstr() function .
strstr(str1,str2) Function is used to determine the string str2 Whether it is str1 The string of . If it is , Then the function returns str2 stay str1 The address that first appeared in ; otherwise , return NULL.
KMP Algorithm .
Reference resources :
http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.html
C++ Code :

边栏推荐
- Kotlin - 验证时间格式是否是 yyyy-MM-dd HH:mm:ss
- VSCODE 安装LATEX环境,参数配置,常见问题解决
- ModuleNotFoundError: No module named ‘jieba.analyse‘; ‘jieba‘ is not a package
- (第一百篇BLOG)写于博士二年级结束-20200818
- Sentry搭建和使用
- qq邮箱接收不到jenkins构建后使用email extension 发送的邮件(timestamp 或 auth.......)
- Flask migrate cannot detect db String() equal length change
- Latex在VSCODE中编译中文,使用中文路径问题解决
- Linked list (linear structure)
- Name six schemes to realize delayed messages at one go
猜你喜欢

Win电脑截图黑屏解决办法

Redis——热点key问题

js中map和forEach的用法

qq邮箱接收不到jenkins构建后使用email extension 发送的邮件(timestamp 或 auth.......)

Sentinel rules persist to Nacos

Code skills - Controller Parameter annotation @requestparam

Présence d'une panne de courant anormale; Problème de gestion de la fsck d'exécution résolu

CTF web practice competition

Utilisation de la carte et de foreach dans JS

Usage of map and foreach in JS
随机推荐
apt命令报证书错误 Certificate verification failed: The certificate is NOT trusted
20201002 VS 2019 QT5.14 开发的程序打包
Warp matrix functions in CUDA
Storage space modifier in CUDA
Record RDS troubleshooting once -- RDS capacity increases dramatically
unittest.TextTestRunner不生成txt测试报告
Sublime Text 配置php编译环境
There are multiple good constructors and room will problem
Solution to the black screen of win computer screenshot
Linked list (linear structure)
Latex参考文献引用失败 报错 LaTeX Warning: Citation “*****” on page y undefined on input line *
由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
Win10: add or delete boot items, and add user-defined boot files to boot items
After reading useful blogs
Pytest (3) parameterize
部署api_automation_test过程中遇到的问题
看完有用的blog
NodeJs - Express 中间件修改 Header: TypeError [ERR_INVALID_CHAR]: Invalid character in header content
CTF three count
Browser scrolling for more implementations