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
classSolution:defcontainsDuplicate(self, nums: List[int])->bool: n =len(nums)return n !=len(set(nums))