Algorithm highlights of interview questions and question Algorithms

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.