Leetcode 28. Implement strStr()
2017-01-29 08:18
246 查看
// naive O(n^2) solution public class Solution { public int strStr(String haystack, String needle) { if (needle.length() == 0) return 0; if (haystack.length() < needle.length()) return -1; // index of i is between [0, haystack-needle] for (int i=0; i<=haystack.length()-needle.length(); i++) { int tmp = i; int j; for (j=0; j<needle.length(); j++) { if (haystack.charAt(tmp) != needle.charAt(j)) break; tmp++; } if (j == needle.length()) return i; } return -1; } }
相关文章推荐
- Sunday算法的一种Java实现(Leetcode28. Implement strStr())
- LeetCode - 28. Implement strStr()
- Leetcode 28. Implement strStr() KMP算法解题
- [LeetCode] 28. Implement strStr() 实现strStr()函数
- LeetCode 28. Implement strStr()
- LeetCode笔记:28. Implement strStr()
- python写算法题: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()
- Leetcode---28. Implement strStr()
- 2017.10.21 LeetCode - 13. Roman to Integer - 28. Implement strStr()
- leetcode 28. Implement strStr()
- leetcode_28. Implement strStr() 字符串模式匹配,返回匹配的首字符位置
- leetcode 28. Implement strStr() (java实现)
- 【C++】【LeetCode】28. Implement strStr()