[转] Facebook 面试的算法题

转载自: http://www.newsmth.net/nForum/article/Algorithm/49305

用PHP实现一下吧.

<?php
function get_start($l, $s) {
$a = array();
foreach($l as $k=>$v) {
$a[$k] = getCharpos2($s, $v);

}
return $a;
}
function getCharpos2($str, $char){
$j = 0;
$arr = array();
$count = substr_count($str, $char);
for($i = 0; $i < $count; $i++){
$j = strpos($str, $char, $j);
$arr[] = $j;
$j = $j+1;
}
return $arr;
}
$l = array("fooo","barr","wing","ding","wing");
$s = "lingmindraboofooowingdingbarrwingmonkeypoundcake";

$leng = strlen($l[0]); // 字符串固定长度
$arr = array();
for($i=0;$i<strlen($s);$i++) {
$tmpstr = substr($s, $i, $leng);
$tmpkey = array_search($tmpstr, $l);
//var_dump($tmpkey);



}

function get_key($str, $arr) {


}



posted on 2012-03-16 18:08  DavidYanXW  阅读(406)  评论(0编辑  收藏  举报