rahul
BAN USERfunction getValidWord($string) {
$map = ["i","like","face","book","facebook"] ;
if(in_array($string,$map)) {
return [$string,NULL];
}
$len = strlen($string)-1;
$residualString = '';
while($len) {
$residualString = $string[$len].$residualString;
if(in_array(substr($string,0,$len),$map)) {
return [substr($string,0,$len),$residualString];
}
$len--;
}
}
$string = 'ilikefacebook';
while($string) {
$result = getValidWord($string);
$string = $result[1];
$finalResult = $finalResult?$finalResult." ":"";
$finalResult = $finalResult.$result[0];
}
class Node {
public $next,$down,$data;
public function __construct($data) {
$this->data = $data;
}
}
function flattenNode($head) {
if($head) {
if($head->next == NULL && $head->down == NULL) {
return $head;
}
while($head) {
$temp = $head->next;
while($head->down) {
$head->next = $head->down;
$head->down = NULL;
$head = $head->next;
}
$head->next = $temp;
$head = $head->next;
}
}
return $head;
}
- rahul November 05, 2018