leetcode28. Implement strStr()
来源:互联网 发布:图像阈值分割算法 编辑:程序博客网 时间:2024/05/17 23:54
28. Implement strStr()
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
解法
双重循环,逐个字母进行比较。
public class Solution { public int strStr(String haystack, String needle) { if (haystack == null || needle == null) { return -1; } int i, j; for (i = 0; i < haystack.length() - needle.length() + 1; i++) { for (j = 0; j < needle.length(); j++) { if (haystack.charAt(i + j) != needle.charAt(j)) { break; } } if (j == needle.length()) { return i; } } return -1; }}
0 0
- [LeetCode28] Implement strStr()
- Leetcode28 Implement strStr()
- LeetCode28:Implement strStr()
- [LeetCode28] Implement strStr()
- Leetcode28: Implement strStr()
- Leetcode28. Implement strStr()
- leetcode28: Implement strStr()
- leetcode28. Implement strStr()
- leetcode28. Implement strStr()
- LeetCode28. Implement strStr()
- leetcode28 Implement strStr()
- LeetCode28. Implement strStr()
- LeetCode28——Implement strStr()
- 【LeetCode28】【 Implement strStr()】length,length(),size()
- Sunday算法的一种Java实现(Leetcode28. Implement strStr())
- Implement strStr()
- Implement strStr()
- Implement strStr()
- TensorFlow学习笔记(一)入门
- GYM 101147 H.Commandos(dp)
- Win10快捷键
- Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfi
- 为什么你应该(从现在开始就)写博客
- leetcode28. Implement strStr()
- Java-事件处理机制
- 如何判断系统大端小端问题
- 算法训练 寒假作业
- 计算机字符编码的科普
- Ubuntu16.04安装dvwa
- 2016.09.29.Java使用集合类时编译问题
- Activity的4种启动模式
- jquery判断文本框是否为空,不为空则用正则表达式判断是否符合要求,不符合清空