Single Number II Solution LeetCode June Day 22

Quoestion:Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.



Python Code:
from collections import defaultdict
class Solution:
    def singleNumber(self, nums: List[int]) -> int:
        d = defaultdict(int)
        for i in nums:
            d[i]+=1
        for i,j in d.items():
            if j==1:

                return i

Post a Comment

0 Comments