Python easiest answer


  • -2
    H

    Assumed that it appears twice. Works for this question anyways

    class Solution(object):
        def singleNumber(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            sum1 = sum(nums)
            sum2 = 3*sum(list(set(nums)))
            return (sum2 - sum1) / 2
    

    How do i use this method but at the same time could input the frequency of that one number instead of assuming twice?


  • 0
    L

    list set means o(n) memory


Log in to reply
 

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