首页 > 其他 > 详细

[LeetCode] Implement strStr()

时间:2014-08-25 13:11:34      阅读:234      评论:0      收藏:0      [点我收藏+]

Implement strStr().

Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.

class Solution {
public:
    char *strStr(char *haystack, char *needle) {
        int len1 = strlen(haystack);
        int len2 = strlen(needle);
        if(len1<len2)
            return NULL;
        char *p = haystack;
        for(int i=0;i<=(len1-len2);i++,p++){
            if(strncmp(p,needle,len2)==0)
                return p;
        }
        return NULL;
    }//end func
};

 

[LeetCode] Implement strStr()

原文:http://www.cnblogs.com/Xylophone/p/3934608.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!