1/4
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress

Merge Sorted Array
class Solution:
def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
"""
Do not return anything, modify nums1 in-place instead.
"""
last = m + n - 1
p_one = m - 1
p_two = n - 1
while last >= 0:
if p_one < 0:
nums1[last] = nums2[p_two]
p_two -= 1
elif p_two < 0:
break
elif nums1[p_one] > nums2[p_two]:
nums1[last] = nums1[p_one]
p_one -= 1
else:
nums1[last] = nums2[p_two]
p_two -= 1
last -= 1

class Solution:
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
intervals.sort(key=lambda i: i[0])
output = [intervals[0]]
for one, two in intervals[1:]:
lastend = output[-1][1]
if one <= lastend:
output[-1][1] = max(lastend, two)
else:
output.append([one, two])
return output

class Solution:
def isValid(self, s: str) -> bool:
stack = []
pairs = {")" : "(", "}" : "{", "]" : "["}
for char in s:
if char in pairs:
if stack and stack[-1] == pairs[char]:
stack.pop()
else:
return False
else:
stack.append(char)
return stack == []
class Solution:
def maxArea(self, height: List[int]) -> int:
n = len(height)
left = 0
right = n - 1
val = 0
while right > left:
water = min(height[left], height[right]) * (right - left)
val = max(val, water)
if height[right] > height[left]:
left += 1
else:
right -= 1
return val