My C++ Solution


  • 0
    class Solution {
    public:
    	int strStr(char *haystack, char *needle) {
    		int len_nd = strlen(needle);
    		if (!len_nd)      return 0;
    		for (int i = 0;*haystack; haystack++,i++)
    			if (*haystack == *needle && strncmp(haystack, needle, len_nd) == 0)
    				return i;
    		return -1;
    	}
    };

  • 0
    K

    What do you mean by
    if (!len_nd) return 0;
    ?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.