Guest User

Untitled

a guest
Oct 16th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. class Solution {
  2. public int strStr(String haystack, String needle) {
  3. if (needle.equals("")) return 0;
  4. if (haystack.equals("")) return -1;
  5. int i = 0;
  6. while (i < haystack.length()) {
  7. int x = 0;
  8. int y = i;
  9. while (y < haystack.length() && x < needle.length() && haystack.charAt(y) == needle.charAt(x)) {
  10. if ((x+1) >= needle.length()) return i;
  11. y++;
  12. x++;
  13. }
  14. i++;
  15. }
  16. return -1;
  17. }
  18. }
Add Comment
Please, Sign In to add comment