We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 72668e7 commit 2714bd7Copy full SHA for 2714bd7
longest-substring-without-repeating-characters/devyejin.py
@@ -0,0 +1,14 @@
1
+# space complexity O(n), time complexity O(1)
2
+class Solution:
3
+ def lengthOfLongestSubstring(self, s: str) -> int:
4
+ seen = {}
5
+ left = 0
6
+ max_length = 0
7
+
8
+ for right, char in enumerate(s):
9
+ if char in seen and seen[char] >= left:
10
+ left = seen[char] + 1
11
+ seen[char] = right
12
+ max_length = max(max_length, right - left + 1)
13
14
+ return max_length
0 commit comments