contains duplicate : leetcode solution in python

class Solution:
    def containsDuplicate(self, nums: List[int]) -> bool:
            freq = 1
            dup = False
            nums_freq_dict = {}
            for each_ele in nums:
                if each_ele not in nums_freq_dict:
                    nums_freq_dict[each_ele] = 1
                    freq += 1
                    nums_freq_dict[each_ele] = freq
                    if freq >= 2:
                        dup = True
                        return True
            if not dup:
                return False

Leave a Comment

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock