Back to course home
0% completed
Vote For New Content
a better approach i think (not using set())
Calvin
Feb 6, 2024
def containsDuplicate(nums): for i in range(len(nums)): if nums[i] in nums[1+i:]: return True return False
0
0
Comments
Comments
Shubham Voraa year ago
Time complexity of the outer loop is O(n). If statement checks whether the nums[i] is in the sublist nums[1+i: ], which takes O(n) time.
So, the overall time complexity is O(n^2).
On this page
Problem Statement
Examples
Solution
Approach 1: Brute Force
Approach 2: Using Hash Set
Approach 3: Sorting