邓英超 发表于 2013-7-30 15:54:36

[google面试题]Write
 a
 program
 to 
determine
 whether
 an
 input 
string
 x 
is
 a 
substring 
of
 another
 input
 string
 y.



(For example,"bat" is a substring of "abate",but not of "beat".) You may use any language you like.

发表于 2013-7-30 16:41:49

Sample Answer(inC++):bool has Substring(const char *str, constchar *find) { if(str == '\0' && find == '\0') return true; for(int i = 0; str != '\0'; i++) { boolfoundNonMatch = false; for(int j = 0; find != '\0'; j++) { if(str != find) { foundNonMatch = true; break; } } if(!foundNonMatch) return true; } return false;}
页: [1]
查看完整版本: [google面试题]Write
 a
 program
 to 
determine
 whether
 an
 input 
string
 x 
is
 a 
substring 
of
 another
 input
 string
 y.