class Solution {
/**
* @param String $s
* @return Integer
*/
function lengthOfLongestSubstring($s) {
$len = strlen($s);
$max = 0;
$tempMax = 0;
$freq = array();
#loop through array
for($i = 0; $i < $len; $i++){
#if IN character in freq array
if(array_key_exists($s[$i], $freq)) {
var_dump( $s[$i]);
$max = max($max, $tempMax);
$tempMax = 0;
$this->resetFreq($freq);
}
else {
#if not in freq array
$freq[$s[$i]] = 1;
$tempMax +=1 ;
}
}
return $max;
}
public function resetFreq(array $freq) : array {
return array();
}
}
Categories