leetcode-3

@爱耍流氓的唐僧  November 6, 2021

简单滑动窗口的实现

class Solution {

    /**
     * @param String $s
     * @return Integer
     */
    function lengthOfLongestSubstring($s) {
        $len = 0 ;
        for($i=0;$i<strlen($s);$i++) {
            $len1 = $this->getMaxString(substr($s, $i));
            $len = $len>=$len1?$len:$len1;
        }
        return $len; 
    }

    function getMaxString($s) {
        for($i=0;$i<strlen($s);$i++) {
            if(strpos($tmp,$s[$i]) !== false){ 
                break; 
            }else{
                $tmp .= $s[$i];
            }
        }
        return strlen($tmp); 
    }
}

添加新评论