面试题之算法集锦,试题算法集锦
思路1:$num){ $tmp[$v]+=$num; } } return $tmp; } function getStringIntersect($str1, $str2){ $temp=stringToChar($str1,1); //$str2的$num用2 就是为了区分 stemp中的原来的1 是 $str1中设置的 $temp=stringToChar($str2,2,$temp); $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; ?>
今天随便浏览网页的时候又发现了这篇文章(一次谷歌面试趣事)
我想起来了 思路二出自这篇文章。
登录后复制
http://www.bkjia.com/PHPjc/1048743.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1048743.htmlTechArticle面试题之算法集锦,试题算法集锦 思路1: 把A去重得到A1 ,B去重得到B1,然后对A1,B1分别进行排序,然后遍历较短的字符串的每个字符是否存在于...