未验证 提交 9097b27c 编写于 作者: K KEQI HUANG 提交者: GitHub

Update 159._Longest_Substring_with_At_Most_Two_Distinct_Characters.md

上级 c1cfdffe
......@@ -9,5 +9,24 @@
```python
class Solution(object):
def lengthOfLongestSubstringTwoDistinct(self, s):
"""
:type s: str
:rtype: int
"""
maps = {}
begin, end, counter, length = 0, 0, 0, 0
while end < len(s):
maps[s[end]] = maps.get(s[end], 0) + 1
if maps[s[end]] == 1:
counter += 1
end += 1
while counter > 2:
maps[s[begin]] -= 1
if maps[s[begin]] == 0:
counter -= 1
begin += 1
length = max(length, end - begin)
return length
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册