Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int strStr(String haystack, String needle) {
- if (needle.equals("")) return 0;
- if (haystack.equals("")) return -1;
- int i = 0;
- while (i < haystack.length()) {
- int x = 0;
- int y = i;
- while (y < haystack.length() && x < needle.length() && haystack.charAt(y) == needle.charAt(x)) {
- if ((x+1) >= needle.length()) return i;
- y++;
- x++;
- }
- i++;
- }
- return -1;
- }
- }
Add Comment
Please, Sign In to add comment