My one line python solution that beats 88% of python submissions

  • 1

    class Solution:

    # @param A, a list of integer
    # @return an integer
    def singleNumber(self, A):
        return (3*sum(list(set(A)))-sum(A))/2

  • 1

    Your solution is actually based on a hash table, i.e. the set() operation. Thus, it uses extra memory, which is not what the problem asked for.

  • 0

    Thanks. I am a beginner of programming so glad to learn that.

Log in to reply

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