Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

class Solution: # @param {integer[]} nums # @return {integer} def singleNumber(self, nums): a= set(nums) a = sum(a)*3 -sum(nums) a = a/2 return a

Brilliant！ However, I really do not know whether the 'set' function in python is an O(n) algorithm.

A great solution if the 'set' function is O(n). However, it needs extra memory

Since set in python is based on hashmap, each operation converting one item in list to set costs O(1), so the complexity should be O(n)

of course set is at least O(n) because it has to visit every element once, right?

@Jenn extra memory

Time complexity is O(n), but space complexity is also O(n) since you build a new set.

Good idea. But when I used it in my C# solution, it caused overflow.

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