Q:

Is this pattern finding method better than KMP or Z-Algorithm implementation?

I was trying to code KMP algorithm. After finishing it, I tried it using java string methods. Here is how I implemented:
String str = "This is easier version of fist";
    String pattern = "is";
    String[] splitStr = str.split(pattern);
    System.out.println("Total occurence of the given pattern in the given string is ="
            +(splitStr.length-1));
    int i=1, count=0;
    for(String st: splitStr){
        if(i<splitStr.length){
        count += st.length();
        System.out.println("Occurence of "+i+" pattern is at index "+count);
        count+=pattern.length();
        i++;
        }
    }

I get below output:
Total occurence of the given pattern in the given string is =3
Occurence of 1 pattern is at index 2
Occurence of 2 pattern is at index 5
Occurence of 3 pattern is at index 27

I know that time complexity of java split() method is O(string length). How does the above code fair against KMP implementation?
Also, if I give this answer in an interview for a pattern matching case instead of KMP, is it a wise thing to do or am I just blowing my chances?

A:

Edit: I fixed my previous complexity calculation.
KMP implementation run with complexity O(n + m), where n = str.length() and m = pattern.length().
Your algorithm also run with complexity O(n + m), but it can skip correct match and produce wrong answer.
Consider this test case:
String str = "apple-orange-apple-apple-apple-orange-apple";
String pattern = "apple";

Your code produce 4 occurences. It should be 5 right?
And this case:
String str = "appleappleappleapple";
String pattern = "apple";

I think it's not blowing your chances, because it show that you able to code your logic in Java and come out with solution.
Good luck with your interview.

