当前位置:网站首页>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 :
边栏推荐
- Redis——大Key问题
- automation - Jenkins pipline 执行 nodejs 命令时,提示 node: command not found
- ctf三计
- [literature reading and thought notes 13] unprocessing images for learned raw denoising
- VSCODE 安装LATEX环境,参数配置,常见问题解决
- Vector types and variables built in CUDA
- Find the highest value of the current element Z-index of the page
- Log (common log framework)
- 实现strStr() II
- ctf-web之练习赛
猜你喜欢
Log (common log framework)
Sparse array (nonlinear structure)
Redis - hot key issues
20201002 VS 2019 QT5.14 开发的程序打包
自学table au
How to try catch statements that return promise objects in JS
Idea announced a new default UI, which is too refreshing (including the application link)
pytest(1) 用例收集规则
Win10:添加或者删除开机启动项,在开机启动项中添加在用户自定义的启动文件
js中正则表达式的使用
随机推荐
sprintf_ How to use s
Latex在VSCODE中编译中文,使用中文路径问题解决
eslint配置代码自动格式化
selenium的web自动化中常用的js-修改元素属性翻页
Render minecraft scenes into real scenes using NVIDIA GPU
unittest. Texttestrunner does not generate TXT test reports
js中对于返回Promise对象的语句如何try catch
Virtualenv and pipenv installation
Functions of tensorrt
Selenium memo: selenium\webdriver\remote\remote_ connection. Py:374: resourcewarning: unclosed < XXXX > solution
There is no way to drag the win10 desktop icon (you can select it, open it, delete it, create it, etc., but you can't drag it)
FE - Weex 使用简单封装数据加载插件为全局加载方法
Shardingsphere JDBC
代码技巧——Controller参数注解@RequestParam
Latex compiles Chinese in vscode and solves the problem of using Chinese path
ModuleNotFoundError: No module named ‘jieba. analyse‘; ‘ jieba‘ is not a package
Latex compilation error I found no \bibstyle &\bibdata &\citation command
Function execution space specifier in CUDA
Win10网络图标消失,网络图标变成灰色,打开网络设置闪退等问题解决
Win10:添加或者删除开机启动项,在开机启动项中添加在用户自定义的启动文件