All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0001_0100.s0028_implement_strstr.Solution Maven / Gradle / Ivy

package g0001_0100.s0028_implement_strstr;

public class Solution {
    public int strStr(String haystack, String needle) {
        if (needle.isEmpty()) {
            return 0;
        }
        for (int i = 0; i <= haystack.length() - needle.length(); i++) {
            if (haystack.substring(i, i + needle.length()).equals(needle)) {
                return i;
            }
        }
        return -1;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy