Algorithm highlights of interview questions and question Algorithms
Idea 1: deduplicate A to A1 and B to obtain B1, and then sort A1 and B1 respectively, check whether each character of a shorter string exists in a longer string. If so, the output problem is: 1. the idea is very simple. This is basically the case for everyone, but there is no bright spot during the interview. 2. If the AB string only contains lowercase letters (It Doesn't Matter), create an array, the key of the array is a-> z, and the value is 0. <? Php function stringToChar ($ str, $ num = 1, $ tmp = null) {if (empty ($ tmp) {$ tmp = array ('A' => 0, 'B' => 0, 'c' => 0, 'D' => 0, 'E' => 0, 'F' => 0, 'G' => 0, 'H' => 0, 'I' => 0, 'J' => 0, 'K' => 0, 'L' => 0, 'M' => 0, 'n' => 0, 'O' => 0, 'p' => 0, 'q' => 0, 'R' => 0,'s '=> 0, 't' => 0, 'U' => 0, 'V' => 0, 'w' => 0, 'x' => 0, 'y' => 0, 'z' => 0 );} $ arr_temp = str_split ($ str, 1); foreach ($ arr_temp as $ v) {if ($ tmp [$ v] <$ num) {$ tmp [$ v] + = $ num;} return $ tmp;} function getStringIntersect ($ Str1, $ str2) {$ temp = stringToChar ($ str1, 1 ); // $ num of str2 uses 2 to distinguish the original 1 in stemp from $ temp = stringToChar ($ str2, 2, $ temp) set in $ str1 ); $ result = ''; foreach ($ temp as $ key => $ value) {if ($ value = 3) {$ result. = $ key ;}} return $ result ;}$ A = "common"; // "hello"; $ B = "month"; // "jeesite "; $ result = getStringIntersect ($ A, $ B); echo $ result;?>
Today, I found this article when I browsed the web page casually (an interesting Google interview)
I think of this article.