Guest User

Untitled

a guest
Oct 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. public class ImplementstrStr {
  2. public int strStr(String haystack, String needle) {
  3. if (needle.equals("")){
  4. return 0;
  5. }
  6. String[] array = haystack.split("");
  7. int n = haystack.length();
  8. int m = needle.length();
  9. if (n<m)
  10. return -1;
  11. for(int i=0; i<n-m+1; i++){
  12. for(int j=0; j<m; j++){
  13. if (haystack.charAt(i+j)!=(needle.charAt(j)))
  14. break;
  15. else
  16. if (j==m-1)
  17. return i;
  18. }
  19. }
  20. return -1;
  21. }
  22. }
Add Comment
Please, Sign In to add comment