: This article mainly introduces the algorithm highlights of the interview questions. For more information about PHP tutorials, see.
- Obtain the characters contained in the AB string, such as ① A = "hello", B = "jeesite", and output "e ", ② A = "common", B = "month", "mno" is output, and the sequence of output strings is not required.
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;
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_tempas $ 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 $ str1. Set $ temp = stringToChar ($ str2, 2, $ temp); $ result = ''; foreach ($ tempas $ key => $ value) {if ($ value = 3) {$ result. = $ key ;}} return $ result ;}$ A = "common"; // "hello"; $ B = "month"; // "jeesite "; $ result = getStringIntersect ($ A, $ B); echo $ result;?>
The above describes the algorithm highlights of the interview questions, including some content, and hope to be helpful to friends who are interested in the PHP Tutorial.