Python solution using set (slow not recommended)

  • 0

    The first solution I came up with and saw that it has not been posted here yet. It was accepted but is not a O(log n) solution. Perhaps something needs to be done so that such a solution will not be accepted? More generally, is this an efficient approach if the O(log n) constraint is not specified?

    class Solution(object):
        def singleNonDuplicate(self, nums):
            :type nums: List[int]
            :rtype: int
            for n in set(nums):
                if (nums.count(n)!=2):
                    return n

Log in to reply

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