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

边栏推荐
- 默认google浏览器打不开链接(点击超链接没有反应)
- Asynchronous data copy in CUDA
- Redis——大Key問題
- ctf三计
- 由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
- 由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决
- FE - weex 开发 之 使用 weex-ui 组件与配置使用
- Log (common log framework)
- FE - 微信小程序 - 蓝牙 BLE 开发调研与使用
- [daily question 1] write a function to judge whether a string is the string after the rotation of another string.
猜你喜欢

js中对于返回Promise对象的语句如何try catch

Hydration failed because the initial UI does not match what was rendered on the server. One of the reasons for the problem

代码技巧——Controller参数注解@RequestParam

ctf三计

Detailed definition of tensorrt data format

Latex warning: citation "*****" on page y undefined on input line*

Pytest (2) mark function

华为MindSpore开源实习机试题

ZZQ的博客目录--更新于20210601

Apt command reports certificate error certificate verification failed: the certificate is not trusted
随机推荐
Function execution space specifier in CUDA
Vscode installation, latex environment, parameter configuration, common problem solving
奇葩pip install
Blog directory of zzq -- updated on 20210601
Présence d'une panne de courant anormale; Problème de gestion de la fsck d'exécution résolu
20201025 visual studio2019 qt5.14 use of signal and slot functions
Nodejs - Express middleware modification header: typeerror [err_invalid_char]: invalid character in header content
(第一百篇BLOG)写于博士二年级结束-20200818
代码技巧——Controller参数注解@RequestParam
Win10桌面图标没有办法拖动(可以选中可以打开可以删除新建等操作但是不能拖动)
记录一次RDS故障排除--RDS容量徒增
部署api_automation_test过程中遇到的问题
Virtualenv and pipenv installation
[daily question 1] write a function to judge whether a string is the string after the rotation of another string.
ModuleNotFoundError: No module named ‘jieba.analyse‘; ‘jieba‘ is not a package
ModuleNotFoundError: No module named ‘jieba. analyse‘; ‘ jieba‘ is not a package
计算属性普通函数写法 和 set get 写法
The default Google browser cannot open the link (clicking the hyperlink does not respond)
eslint配置代码自动格式化
Find the highest value of the current element Z-index of the page