Python 1 line solution


  • 0
    M

    Remove the duplicate using set()
    The difference between twice the sum of the duplicates-removed list and the sum of the original list would be the value that only appeared once.

    def singleNumber(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
    
            return 2*sum(list(set(nums))) - sum(nums)
    

Log in to reply
 

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