码迷,mamicode.com
首页 > 其他好文 > 详细

28. Implement strStr()

时间:2016-08-10 22:46:18      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

public class Solution {
    public int strStr(String haystack, String needle) {
        if(haystack.equals("")&&needle.equals(""))
            return 0;
        int size1=haystack.length();
        int size2=needle.length();
        int res=-1;
        for(int i=0;i<=size1-size2;i++)
        {
            int head=i;
            int i1=i;
            int i2=0;
            while(i1<size1&&i2<size2)
            {
                if(haystack.charAt(i1)==needle.charAt(i2))
                {
                    i1++;
                    i2++;
                }
                else
                    break;
            }
            if(i2==size2)
            {
                res=head;
                break;
            }
        }
        return res;
    }
}

 

28. Implement strStr()

标签:

原文地址:http://www.cnblogs.com/aguai1992/p/5758579.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!