-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2.php
More file actions
34 lines (31 loc) · 810 Bytes
/
task2.php
File metadata and controls
34 lines (31 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
class MaximumUniqueSubstring
{
public function findMaximumUniqueSubstring($str)
{
$strlen = strlen($str);
$set = array();
$startIndex = 0;
$endIndex = 0;
$maxSubstringLength = 0;
$maxSubstringIndex = 0;
while ($endIndex < $strlen)
{
if (!empty($set[$str[$endIndex]]) && $set[$str[$endIndex]] > $startIndex)
{
$startIndex = $set[$str[$endIndex]];
}
if ($endIndex - $startIndex + 1 > $maxSubstringLength)
{
$maxSubstringLength = $endIndex - $startIndex + 1;
$maxSubstringIndex = $startIndex;
}
$set[$str[$endIndex]] = $endIndex + 1;
$endIndex++;
}
return substr($str, $maxSubstringIndex, $maxSubstringLength);
}
}
//$obj = new MaximumUniqueSubstring();
//echo $obj->findMaximumUniqueSubstring('aabcdAbc');
?>