File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
container-with-most-water
longest-substring-without-repeating-characters Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def maxArea (self , height : List [int ]) -> int :
3
+ left = 0
4
+ right = len (height ) - 1
5
+
6
+ maxWater = 0
7
+
8
+ while left <= right :
9
+ hori = right - left
10
+ vert = min (height [left ], height [right ])
11
+ maxWater = max (maxWater , hori * vert )
12
+
13
+ if height [left ] < height [right ]:
14
+ left += 1
15
+ else :
16
+ right -= 1
17
+
18
+ return maxWater
19
+ # TC: O(n) SC: O(1)
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def lengthOfLongestSubstring (self , s : str ) -> int :
3
+ left = 0
4
+ seen = {}
5
+ res = 0
6
+
7
+ for right , curr in enumerate (s ):
8
+ if curr in seen :
9
+ left = max (left , seen [curr ] + 1 )
10
+ res = max (res , right - left + 1 )
11
+ seen [curr ] = right
12
+
13
+ return res
14
+
15
+ ## TC:O(n), SC:O(min(m,n)) where n is len(s) and m is size(seen)
You can’t perform that action at this time.
0 commit comments