leetcode 28
来源:互联网 发布:手机淘宝不能追加评论 编辑:程序博客网 时间:2024/06/06 15:45
leetcode 28. Implement strStr()
题目:实现strStr()
strStr()函数是求解子串在父串中第一次出现的位置,否则返回-1;
测试用例设计:
- 子串长度>父串长度,返回-1;
- 子串长度=父串长度,如果相同,返回0,否则返回-1;(包含特殊情况,父串子串均为空串)
- 子串长度<父串长度
- 子串不包含在父串中,返回-1;
- 子串包含在父串中,返回第一次出现的位置;
代码如下:
public int strStr(String haystack, String needle) { if(haystack.length()<needle.length()) return -1; else if(haystack.length()==needle.length()&&haystack.equals(needle))return 0; for(int i = 0;i<=haystack.length()-needle.length();i++){ if(haystack.substring(i, i+needle.length()).equals(needle)) return i; } return -1; }
0 0
- leetcode 28
- LeetCode #28
- leetcode 28
- leetcode 28: Merge Intervals
- LeetCode(28)Implement Strstr()
- [leetcode 28] Implement strStr()
- LeetCode[28]Implement strStr()
- leetcode-28 Implement strStr()
- [LeetCode 28]Implement strStr()
- [leetcode]28 Same Tree
- leetcode 28 Implement strStr()
- Leetcode 28 Implement strStr()
- LeetCode 28 - Implement strStr()
- LeetCode 28:Implement strStr()
- leetcode 28 -- Implement strStr()
- leetcode[28]:Implement strStr()
- leetcode 28: Implement strStr()
- Leetcode #28 Implement strStr()
- 【Shell】把某一文件夹下所有文件名或者路径存入TXT文档
- RabbitMQ用户角色及权限控制
- Bean named 'xxx' must be of type xxx , but was actually of type [com.sun.proxy.$Proxy189]
- windows系统桌面右下角出现不是正版提示水印的解决办法
- iOS
- leetcode 28
- Win7 IE报错.NET controls is disabled
- AOP(XML)【理解】【应用】【重点】
- Python中Iterable与Iterator
- 读EasyPR开发详解实践感想1
- 4、scrapy内置服务
- Unity3d屏幕截图方法
- initramfs文件系统的制作和移植
- BZOJ4870: [Shoi2017]组合数问题