This repository was archived by the owner on Oct 4, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def lengthOfLongestSubstring (self , s : str ) -> int :
3
+ res = 0
4
+ d = {}
5
+ i = 0
6
+ j = 0
7
+ while j < len (s ):
8
+ if s [j ] in d :
9
+ i = max (i ,d [s [j ]])
10
+ d [s [j ]] = j + 1
11
+ j += 1
12
+ res = max (res ,j - i )
13
+ return res
14
+
15
+
16
+
17
+
18
+
19
+ class Solution :
20
+ def lengthOfLongestSubstring (self , s : str ) -> int :
21
+ str_list = []
22
+ max_length = 0
23
+
24
+ for x in s :
25
+ if x in str_list :
26
+ str_list = str_list [str_list .index (x )+ 1 :]
27
+
28
+ str_list .append (x )
29
+ max_length = max (max_length , len (str_list ))
30
+
31
+ return max_length
32
+
33
+
34
+ class Solution :
35
+ def lengthOfLongestSubstring (self , s : str ) -> int :
36
+ max_len = 0
37
+ d = {}
38
+ i = 0
39
+ j = 0
40
+ while j < len (s ):
41
+ if s [j ] in d :
42
+ i = max (d [s [j ]],i )
43
+ max_len = max (max_len ,j - i + 1 )
44
+ d [s [j ]] = j + 1
45
+ j += 1
46
+ return max_len
47
+
48
+
49
+
50
+ class Solution :
51
+ def lengthOfLongestSubstring (self , s : str ) -> int :
52
+ n = len (s )
53
+ ans = 0
54
+ d = {}
55
+ i = 0
56
+ for j in range (n ):
57
+ if s [j ] in d :
58
+ i = max (d [s [j ]],i )
59
+
60
+ ans = max (ans ,j - i + 1 )
61
+ d [s [j ]] = j + 1
62
+ return ans
You can’t perform that action at this time.
0 commit comments