author: Blankj blog : http://blankj.com time : 2017/05/01 desc :
| 9 | * </pre> |
| 10 | */ |
| 11 | public 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected