Leetcode - Sort List (Python)

preview_player
Показать описание
October 2020 Leetcode Challenge
Leetcode - Sort List # 148
Рекомендации по теме
Комментарии
Автор

OMG! The Bottom Up O(1) space is just stupidly hard! And I don't know if I could come up with merge sort on the spot, it would definitely take some time, maybe even the whole interview. But Tim! Your bubble sort was idea was awesome! I digress though...it was very good reviewing merge sort, and this problem I think does a good job combining two other leetcode questions: 1. Merge two linked lists 2. Find the mid point of a linked list.

janmichaelaustria
Автор

can't really think of the third solution. The first two are well explained! Thank you~~

elegentt
Автор

hello, i'm back. :)
i've run into another problem, i hope you could help me out again. :)
so i'm using the code gave last time (of course!)
i want to use filters in the set, is it possible to use the whole filter in just 1 sentence of if function?
i have a lot of filter and it would be very long if i write all of it. :( (it is more than 20)
thank you in advance. :)


A = ["a", "b", "c", "d", "d"]
B = ["e", "f", "g", "h", "i"]
C = ["j", "k", "l", "m", "n"]

#Filters
FilterA = set(["a", "f", "j", "g", "h", "i"])
FilterB = set(["a", "f", "j", "g", "h", "i"])
FilterC = set(["a", "f", "j", "g", "h", "i"])
FilterD = set(["a", "f", "j", "g", "h", "i"])
FilterE = set(["a", "f", "j", "g", "h", "i"])
FilterF = set(["a", "f", "j", "g", "h", "i"])
FilterG = set(["a", "f", "j", "g", "h", "i"])
FilterH = set(["a", "f", "j", "g", "h", "i"])
FilterI = set(["a", "f", "j", "g", "h", "i"])
FilterJ = set(["a", "f", "j", "g", "h", "i"])

import itertools
import csv

# combo of each group
C1 = list(itertools.combinations(A, 1))
C2 = list(itertools.combinations(B, 4))
C3 = list(itertools.combinations(C, 1))

with open('File.csv', 'w', newline='') as csvfile:
w = csv.writer(csvfile, delimiter=', ')

# combine all combo into carterisian product
for a, b, c in list(itertools.product(C1, C2, C3)):
#filter in with 3 match ONLY

if sum([1 for i in [a[0], b[0], b[1], b[2], b[3], c[0]] if i in FilterA]) = 3:

w.writerow([a[0], b[0], b[1], b[2], b[3], c[0]])
# print(a[0], b[0], b[1], b[2], b[3], c[1])

richarddevera