class Solution(object): def singleNumber(self, nums): """ :type nums: List[int] :rtype: int """ return 2*sum(set(nums)) - sum(nums)
Your solution relies on using set(). But doesn't set() use extra memory to remove all the dups?
You are right, It does use extra memory. But I can't think of a solution without extra memory of O(n). There are solution O(nlog(n)) without extra memory. What do you think?
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.