Java solution with ArrayList and HashSet, O(1) per adding. O(nlogn) per merging. Beats 97%.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.