Click here to see the full article post
class Solution(object): def containsDuplicate(self, nums): if len(nums) > len(set(nums)): return True return False
Approach #3 (Hash Table) - this is not getting accepted. Please check. Its giving TLE.
I tried using HashMap and HashSet in Java but its giving TLE for both for the test case ranging from 0, 1, 2.......29999. As the numbers are not given to be sorted, binary search cant be used here. For unsorted array, in worst case O(n) would be required.
Infact, on pasting this dataset into Eclipse, eclipse is giving error "The code of method main(String) is exceeding the 65535 bytes limit"
HashSet executes the time limit error. Agree with @hu26
Can find a better solution here:
I tried using an ArrayList and a HashSet as a data structure for holding the values of the array and testing for contains(). Got time limit exceeded for both. I had to remove the else statement after the if (hashset.contains()). When compiled that code shouldn't be any different right?
I know it is the easiest question of all , but this is the first time I cracked the right soln to sort under 2 mins and get accepted in 1st try . can you give me tips to solve maximum question with same approach.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.