FTPrep, 28 Implement strStr()
来源:互联网 发布:女生自夸的网络句子 编辑:程序博客网 时间:2024/06/16 19:29
思路挺简单的,做了一些edge case的判断,其实都可以包括在代码里,比如
if(shortLen==0 && longLen==0) return 0;
if(shortLen==0 || shortLen>longLen) return -1;
public class Solution { public int strStr(String haystack, String needle) { int shortLen=needle.length(); int longLen=haystack.length(); for(int head=0; head<longLen-shortLen+1; ++head){ if(haystack.substring(head, head+shortLen).equals(needle)) // 对于空串"", substring(0,0) 还是空串 return head; } return -1; }}// 这题就是要记住substring(start, end) 前开后闭的方式就好。
阅读全文
0 0
- FTPrep, 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()
- 28-e-Implement strStr()
- #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()
- 28Implement strStr()
- #28 Implement strStr()
- 五分钟读懂SIGIR 2017前沿技术研究成果
- 模糊匹配并替换
- SQL Server DATEPART() 函数
- 深入理解JVM—JVM内存模型
- MySQL LeftJoin优化未果问题
- FTPrep, 28 Implement strStr()
- Markdown
- Keras中的多分类损失函数categorical_crossentropy
- linux共享内存
- 吊炸天!74款APP完整源码!
- 如何学习嵌入式软件
- java关键词全文搜索实例
- 两种方式避免除掉App启动白屏,有待完善!!!
- 计算机网络基础知识总结