Skip to content

a "Time Limit Exceeded" issue. #4

@peoplehlj

Description

@peoplehlj

https://github.com/mengli/leetcode/blob/master/ImplementStrStr.java#L22

Thanks for your code. But I found an issue in you code, as below snippet:
if (a >= len1 || haystack.charAt(a) != needle.charAt(b)) {
match = false;
break;
}
I think that we can change it to:
if ( haystack.charAt(a) != needle.charAt(b)) {
if (a >= len1) return null;
match = false;
break;
}
will make sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions