動機
紀錄
Sol
from collections import defaultdict
def solution(A):
cnts = defaultdict(int)
idx = {}
for i,n in enumerate(A):
cnts[n] += 1
if n not in idx:
idx[n] = i
i = float('inf')
for k,v in filter(lambda kv: kv[1] == 1, cnts.items()):
i = min(i, idx[k])
return A[i] if i != float('inf') else -1