Given a string, find the length of the **longest substring** without repeating characters.

**Example 1:**

1 2 3 |
<strong>Input: </strong>"abcabcbb" <strong>Output: </strong>3 <strong>Explanation:</strong> The answer is <code>"abc"</code>, with the length of 3. |

**Example 2:**

1 2 3 |
<strong>Input: </strong>"bbbbb" <strong>Output: </strong>1 <strong>Explanation: </strong>The answer is <code>"b"</code>, with the length of 1. |

**Example 3:**

1 2 3 4 |
<strong>Input: </strong>"pwwkew" <strong>Output: </strong>3 <strong>Explanation: </strong>The answer is <code>"wke"</code>, with the length of 3. Note that the answer must be a <strong>substring</strong>, <code>"pwke"</code> is a <em>subsequence</em> and not a substring. |

PHPcode :

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
class Solution { function lengthOfLongestSubstring($s) { $tmp = []; $max = 0; for($i=0;$i< strlen($s); $i++){ $k = array_search($s[$i], $tmp); if($k !== false){ array_splice($tmp, 0, $k+1); } $tmp[] = $s[$i]; $max = $max > count($tmp) ? $max: count($tmp); } return $max; } } |