php 实现字符串最大子串长度
2021-05-12 15:30
标签:子串 cti 字符 nbsp each code for val php php 实现字符串最大子串长度 标签:子串 cti 字符 nbsp each code for val php 原文地址:https://www.cnblogs.com/songyanan/p/12006040.html求字符串最大子串长度
php
class zif
{
public function sz($str)
{
$strsz = str_split($str);
$zi = [];
$len = [];
foreach ($strsz as $val) {
if (in_array($val, $zi)) {
$c = count($zi);
array_push($len, $c);
$zi = [];
}
array_push($zi, $val);
}
if (!empty($zi)) {
$c = count($zi);
array_push($len, $c);
$zi = [];
}
return max($len);
}
}
$s = new zif();
$j = $s->sz(‘qwerghhjhn‘);
echo $j;