1. 程式人生 > >28 Implement strStr()

28 Implement strStr()

class Solution {
public:
	int strStr(string haystack, string needle) {
		if (!needle.size())return 0;
		for (int i = 0; i < haystack.size(); ++i) {
			bool flag = false;
			if (haystack[i] == needle[0]) {
				for (int j = 0; j < needle.size(); ++j) {
					if (haystack[i + j] != needle[j]) {
						flag =
true; break; } } if (!flag)return i; } } return -1; } };