Pergunta de entrevista da empresa Meta

bool regular_expression_match(char* pattern, char* string) and pattern can contain kleene star.

Respostas da entrevista

Sigiloso

30 de mar. de 2013

Do you mean pattern can only normal characters or star? Will other special characters be included, e.g. '?', '+', '{}', '[]', etc.?

Sigiloso

3 de mai. de 2013

bool rep(char* pattern, char* string) { if ((pattern[0] == 0) && (string[0] == 0)) return 1; if ((pattern[0] == 0) || (string[0] == 0)) return 0; if (pattern[1] == '*') { return (match(pattern, string) && (rep(pattern+2,string) || rep(pattern,string+1))); } else { return (match(pattern, string) && rep(pattern+1, string+1)); } } bool match(char* pattern, char* string) { if (*pattern == '.') return 1; return (*pattern == *string); }