Skip to content

Commit 63a7635

Browse files
committed
[Leo] 6th Week solutions (partial solutions for the first two Qs)
1 parent 3e99718 commit 63a7635

File tree

2 files changed

+34
-0
lines changed
  • container-with-most-water
  • longest-substring-without-repeating-characters

2 files changed

+34
-0
lines changed

container-with-most-water/Leo.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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)

0 commit comments

Comments
 (0)