当前位置:网站首页>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 :

边栏推荐
- 由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决
- Self cultivation of programmers - Reflection on job hunting
- 重载全局和成员new/delete
- 2020-9-23 use of QT timer qtimer class.
- qq邮箱接收不到jenkins构建后使用email extension 发送的邮件(timestamp 或 auth.......)
- Three suggestions for all students who have graduated and will graduate
- Warp shuffle in CUDA
- Solution to the black screen of win computer screenshot
- Latex error: the font size command \normalsize is not defined problem solved
- VSCODE 安装LATEX环境,参数配置,常见问题解决
猜你喜欢

CTF web practice competition

Sublime text configuring PHP compilation environment

Latex compilation error I found no \bibstyle &\bibdata &\citation command

Code skills - Controller Parameter annotation @requestparam

Redis - grande question clé

Latest CUDA environment configuration (win10 + CUDA 11.6 + vs2019)

Redis - big key problem

js中map和forEach的用法

Solution to the black screen of win computer screenshot

由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
随机推荐
ctf-web之练习赛
Redis - cluster data distribution algorithm & hash slot
web自动化切换窗口时报错“list“ object is not callable
Apt command reports certificate error certificate verification failed: the certificate is not trusted
Sentry搭建和使用
计算属性普通函数写法 和 set get 写法
Deployment API_ automation_ Problems encountered during test
由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
Unexpected inconsistency caused by abnormal power failure; Run fsck manually problem resolved
Tensorrt command line program
automation - Jenkins pipline 执行 nodejs 命令时,提示 node: command not found
CTF web practice competition
Build learning tensorflow
Warp matrix functions in CUDA
PgSQL学习笔记
There are multiple good constructors and room will problem
Loops in tensorrt
Latex在VSCODE中编译中文,使用中文路径问题解决
ZZQ的博客目录--更新于20210601
Pytest (2) mark function