a108: 公共元素
Tags :
Accepted rate : 93人/98人 ( 95% ) [非即時]
評分方式:
Strictly

最近更新 : 2022-08-18 02:00

Content

Given two lists, write a program to return a list that contains only the common elements between the lists (without duplication). Make sure your program works on two lists of different sizes.

Input

Two list of int a,b

The length of a and b may not be equal

Output

A list of non-repeat common elements in ascending order

Sample Input #1
1 2 3 4 5 3 88
6 4 5 5 5 5 3 1 9 10 456 23
Sample Output #1
1 3 4 5
Sample Input #2
13 12 15 3 12 13 7 8 18 6
4 15 15 8 0 3 17 8 1 15
Sample Output #2
3 8 15
Sample Input #3
15 6 12 16 9 13 3 15 17 17
15 8 13 9 12 9 11 2 10 5
Sample Output #3
9 12 13 15
測資資訊:
記憶體限制: 64 MB
不公開 測資點#0 (33%): 1.0s , <1K
不公開 測資點#1 (33%): 1.0s , <1K
不公開 測資點#2 (34%): 1.0s , <1K
Hint :

Brute force: two loops O(N^2)

Pruning brute force: sort before loops O(N log N)

Set: O(N log N)

also numpy has function to do this

Tags:
出處:
[管理者:
kichan@g.pui... (陳嘉賢CHAN KA IN)
]


ID User Problem Subject Hit Post Date
沒有發現任何「解題報告」