ThinkinMonke
HomeBlogsAbout
HomeBlogAbout
    Blog
    DSA Walkthrough - 03

    Table of Contents

    DSA Walkthrough - 03

    Walkthrough of the problem "Contains Duplicate"

    January 7, 2026
    1 min
    Article
    DSA
    LeetCode
    Set
    Array
    Python
    DSA Walkthrough - 03
    Algorithm

    Table of Contents

    Intro

    • The problem is very simple, we have to find if any number is repeating more than once, if yes then we return true or we return false

    First approach

    • My first approach was very different and was not accurate enough. What I did was to create a variable count and store the number that is repeating more than once.
    • Later after referring the sources, i realised that what number is repeating doesnt matter because we only check if any one of the number is repeating.

    Solution

    • so the solution is pretty simple, we just check the length of the array with the length of the array in a set.
    • We store them in a set then we calculate the len(set(nums)).
    • Then we compare the original array's length with the length of the set.
    • Returrn true if the condition is satisfied or we return false.
    • So the final step would look like the given code snippet below

    Code

    class Solution:
        def containsDuplicate(self, nums: List[int]) -> bool:
            n = len(nums)
            return n != len(set(nums))
                
    

    Conclusion

    |> Check out my other DSA walkthrough : https://maddyscave.vercel.app/blog/DSA-01

    Published on January 7, 2026

    Estimated reading time: 1 minutes

    Share this article:

    Series: DSA Walkthrough

    Part 3 of 7
    Back to all posts

    You Might Also Like

    DSA Walkthrough - 05
    Algorithm
    2 min

    DSA Walkthrough - 05

    Walkthrough of the problem "Top K frequent Elements"

    Read more
    DSA Walkthrough - 04
    Algorithm
    2 min

    DSA Walkthrough - 04

    Walkthrough of the problem "Group Anagrams"

    Read more
    DSA Walkthrough - 02
    Algorithm
    2 min

    DSA Walkthrough - 02

    Walkthrough of the problem "Search in Rotated Sorted Array"

    Read more

    Table of Contents