@@ -0,0 +1,1071 @@
+package com.yan.leetcode;%0A%0Apublic class ImplementstrStr %7B%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09String haystack = %22dsfewrhsfewrdfsdf%22;%0A%09%09String needle = %22ewr%22;%0A%09%09System.out.println(strStr(haystack, needle));%0A%09%7D%0A%0A%09private static int strStr(String haystack, String needle) %7B%0A%09%09if (haystack.length() == 0 && needle.length() == 0) %7B%0A%09%09%09return 0;%0A%09%09%7D%0A%09%09if (needle.length() %3E haystack.length()) %7B%0A%09%09%09return -1;%0A%09%09%7D%0A%09%09for (int i = 0; i %3C= haystack.length() - needle.length(); i++) %7B%0A%09%09%09if (needle.equals(haystack.substring(i, i + needle.length()))) %7B%0A%09%09%09%09return i;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return -1;%0A%09%7D%0A%0A%09private static int strStr2(String haystack, String needle) %7B%0A%09%09if (haystack == null %7C%7C needle == null)%0A%09%09%09return -1;%0A%09%09if (needle.length() %3E haystack.length())%0A%09%09%09return -1;%0A%09%09for (int i = 0; i %3C= haystack.length() - needle.length(); i++) %7B%0A%09%09%09boolean successFlag = true;%0A%09%09%09for (int j = 0; j %3C needle.length(); j++) %7B%0A%09%09%09%09if (haystack.charAt(i + j) != needle.charAt(j)) %7B%0A%09%09%09%09%09successFlag = false;%0A%09%09%09%09%09break;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09if (successFlag)%0A%09%09%09%09return i;%0A%09%09%7D%0A%09%09return -1;%0A%09%7D%0A%0A%7D%0A

implement strStr