Contains Duplicate Leetcode Solution

Hello coders, In this article, I am going to write another solution for another Leetcode Problem that is ” Contains Duplicate Leetcode Solution “.

Problem statement:

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

Example 1:

Input: nums = [1,2,3,1]
Output: true

Example 2:

Input: nums = [1,2,3,4]
Output: false

Example 3:

Input: nums = [1,1,1,3,3,4,3,2,4,2]
Output: true

Contains Duplicate Leetcode Solution in python

#Contains Duplicate Leetcode Solution in python

class Solution:
    def containsDuplicate(self, nums: List[int]) -> bool:
        if len(set(nums))<len(nums):
            return 1
            return 0
#Contains Duplicate Leetcode Solution in python

Disclaimer: This problem(Contains Duplicate Leetcode solution) is originally created by LeetcodeCodesagar only provides a solution for it. This solution is only for Educational and learning purposes.

Leave a Comment