不幸的是,我相信您仅限于线性
O(N)解,因为所有的并集将是两个集合中元素的组合。
template<typename S>S union_sets(const S& s1, const S& s2){ S result = s1; result.insert(s2.cbegin(), s2.cend()); return result;}
不幸的是,我相信您仅限于线性
O(N)解,因为所有的并集将是两个集合中元素的组合。
template<typename S>S union_sets(const S& s1, const S& s2){ S result = s1; result.insert(s2.cbegin(), s2.cend()); return result;}