Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 051ee78

Browse files
Create lengthOfLongestSubstring.py
1 parent 4869155 commit 051ee78

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def lengthOfLongestSubstring(self, s):
3+
d, j, ans = {}, 0, 0
4+
for i, c in enumerate(s):
5+
if c in d and d[c] >= j:
6+
j = d[c] + 1
7+
ans = max(ans, i-j+1)
8+
d[c] = i
9+
return ans
10+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /