My Python solution using list comprehensions


  • 0
    J
    class Solution(object):
        def singleNumber(self, nums):
            """
            :type nums: List[int]
            :rtype: List[int]
            """
            return [i for i in nums if nums.count(i) == 1]
    a = Solution()
    print a.singleNumber([1, 2, 1, 3, 2, 5])
    

  • 0
    J

    Don't know why time limit exceeded if solution is very simple


  • 0
    F

    Because list.count(element) is not linear.


Log in to reply
 

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