Problem 3 and 4
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
class Solution:
|
||||
def lengthOfLongestSubstring(self, s: str) -> int:
|
||||
count = 0
|
||||
current = []
|
||||
solutions = {}
|
||||
for c in s:
|
||||
if c in current:
|
||||
solutions[count] = current
|
||||
idx = current.index(c)
|
||||
current = current[idx + 1:]
|
||||
count -= idx + 1
|
||||
current.append(c)
|
||||
count += 1
|
||||
solutions[count] = current
|
||||
return max(solutions.keys())
|
||||
|
||||
5
0004-median-of-two-sorted-arrays/solution.py
Normal file
5
0004-median-of-two-sorted-arrays/solution.py
Normal file
@@ -0,0 +1,5 @@
|
||||
class Solution:
|
||||
def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
|
||||
nums1 = sorted(nums1 + nums2)
|
||||
length = len(nums1)
|
||||
return nums1[length//2] if length % 2 == 1 else float(sum(nums1[length//2-1:length//2+1]))/2
|
||||
Reference in New Issue
Block a user