Pregunta de entrevista de Meta

search needle in haystack problem

Respuesta de la entrevista

Anónimo

5 abr 2012

But this can fail at some point.. void search(string needle, string hystack) { int cnt = 0, i, j; for(i = 0; i < hystack.size(); i++) { cnt = 0; if(hystack[i] == needle[0] && (i+needle.size()-1) < hystack.size()) { for(j = i; j < (i+needle.size()); j++) if(hystack[j] != needle[j-i]) break; else cnt++; } if(cnt == needle.size()) cout << true << endl; } }