#P108. 公共元素
公共元素
題目描述
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.
輸入格式
Two list of int a,b
The length of a and b may not be equal
輸出格式
A list of non-repeat common elements in ascending order
Samples
["1 2 3 4 5 3 88\r\n6 4 5 5 5 5 3 1 9 10 456 23","13 12 15 3 12 13 7 8 18 6\r\n4 15 15 8 0 3 17 8 1 15","15 6 12 16 9 13 3 15 17 17\r\n15 8 13 9 12 9 11 2 10 5"]
["1 3 4 5","3 8 15","9 12 13 15"]
提示
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
原始資料
- Zero1 題號:
a108 - Hydro 題號:
Z0108 - Locale:
zh_TW - Display:
open