28. Implement strStr()

来源:互联网 发布:2016淘宝开店书籍推荐 编辑:程序博客网 时间:2024/05/12 10:04
public class Solution {    public int strStr(String haystack, String needle) {        /**        int l1 = haystack.length();int l2 = needle.length();char[] haystack1 = haystack.toCharArray();char[] needle1 = needle.toCharArray();int i = 0;int j = 0;for(i = 0;i <= l1 - l2;i++){for(j = 0;j < l2;j++){if(haystack1[i+j] != needle1[j]){break;}}if(j == l2){return i;}}return -1;**/return haystack.indexOf(needle);}    }

0 0
原创粉丝点击