MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / strStr

Method strStr

src/com/blankj/easy/_0028/Solution.java:12–22  ·  view source on GitHub ↗
(String haystack, String needle)

Source from the content-addressed store, hash-verified

10 */
11public class Solution {
12 public int strStr(String haystack, String needle) {
13 int l1 = haystack.length(), l2 = needle.length();
14 if (l1 < l2) return -1;
15 for (int i = 0; ; i++) {
16 if (i + l2 > l1) return -1;
17 for (int j = 0; ; j++) {
18 if (j == l2) return i;
19 if (haystack.charAt(i + j) != needle.charAt(j)) break;
20 }
21 }
22 }
23
24 public static void main(String[] args) {
25 Solution solution = new Solution();

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected