diff --git a/contains-duplicate/codyman0.py b/contains-duplicate/codyman0.py new file mode 100644 index 000000000..1cc2b3e02 --- /dev/null +++ b/contains-duplicate/codyman0.py @@ -0,0 +1,16 @@ +""" +https://leetcode.com/problems/contains-duplicate/ +""" + +# Time complexity : O(n) + + +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + sortedArray = sorted(nums) + for i in range(len(sortedArray)): + if i == len(sortedArray) - 1: + return False + if sortedArray[i] == sortedArray[i + 1] : + return True + return False