-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.py
More file actions
31 lines (24 loc) · 738 Bytes
/
Copy path3.py
File metadata and controls
31 lines (24 loc) · 738 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = ['"wuyadong" <wuyadong311521@gmail.com>']
class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
length = 0
s_s = dict()
for i, c in enumerate(s):
if c not in s_s:
s_s[c] = i
length = length if length > len(s_s) else len(s_s)
else:
need_remove = s_s[c]
for k, v in s_s.items():
if v <= need_remove:
del s_s[k]
s_s[c] = i
return length
if __name__ == "__main__":
print Solution().lengthOfLongestSubstring("dvdf")