<?php
class Node {
public $value;
public $next = null; // next node
public $prev = null; // previous node
public function __construct($value) {
$this->value = $value;
}
}
class Palindrome {
/**
•@param string $word
•@return bool */
public static function isPalindrome($head, $tail){
if ($head == null)
return true;
while ($head != $tail){
if ($head->value != $tail->value)
return false;
$head = $head->next;
$tail = $tail->prev;
}
return true;
}
}
$head = new Node(1);
$firstNode = new Node(2);
$secondNode = new Node(3);
$tail = new Node(4);
$head->next = $firstNode;
$firstNode->prev = $head;
$firstNode->next = $secondNode;
$secondNode->prev = $firstNode;
$secondNode->next = $tail;
echo Palindrome::isPalindrome($head, $tail);
<?php interface LRUCache{ /** •@param string $key •@param string $value •@return bool $result • •Stores value against the key in the cache */ public function insertIntoCache($key,$value); /** •@param string $key •@return string $value •Gets the value of a key from the cache */ public function getFromCache($key); /** Purge the entire cache */ public function purgeCache(); /** •@return int $count •Gets the number of successful cache hits so far */ public function allCacheHits(); /** •@return int $count •Gets the number of unsuccessful cache hits so far **/ public function allCacheMissed(); } class Cache implements LRUCache{ // int the max number of elements the cache supports private $capacity; // Array representing a naive hashmap (TODO needs to pass t
Comments
Post a Comment