LeetCode28-实现strStr()
LeetCode28-实现strStr()
通过切割字符串实现
| public int strStr(String haystack, String needle) { int n = needle.length(); if (n == 0) { return 0; } for (int i = 0; i < haystack.length(); i++) { if (i + n <= haystack.length() && haystack.substring(i, i + n).equals(needle)) { return i; } } return -1; }
|