반응형
Define a function that removes duplicates from an array of numbers and returns it as a result.
The order of the sequence has to stay the same.
Solution:
def distinct(seq: list[int]) -> list[int]:
result = []
for i in seq:
if i not in result:
result.append(i)
return result
def distinct(seq: list[int]) -> list[int]:
return sorted(set(seq), key=seq.index)
def distinct(seq: list[int]) -> list[int]:
return list(dict.fromkeys(seq))
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
0212. Reversed sequence (0) | 2023.02.13 |
---|---|
0210. Is it a number? (0) | 2023.02.10 |
0209. Sort the Gift Code (0) | 2023.02.09 |
0209. Sort Out The Men From Boys (0) | 2023.02.09 |
0207. Divide and Conquer (0) | 2023.02.08 |