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

Class Solution

src/com/blankj/easy/_0028/Solution.java:11–29  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/05/01 desc :

Source from the content-addressed store, hash-verified

9 * </pre>
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();
26 System.out.println(solution.strStr("12345", "23"));
27 System.out.println(solution.strStr("12345", ""));
28 }
29}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected