Implement strStr().code
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.string
有substring,爲什麼不用。io
public class Solution { public int strStr(String h, String n) { int len = n.length(); for (int i = 0; i <= h.length()-len; i++) { if (h.substring(i, i+len).equals(n)) return i; } return -1; }