We're a place where coders share, stay up-to-date and grow their careers.
Based on the code you've given:
nums.sort(): Is O(nlogn) where n = size of original array. Because array is already sorted then you don't need to sort again anyway.
nums.sort()
You can also use a Map to keep track of already seen items.
The example shows integers but the problem statement does not mention any restrictions on the types. Will this work on any type?
Based on the code you've given:
nums.sort()
: Is O(nlogn) where n = size of original array. Because array is already sorted then you don't need to sort again anyway.You can also use a Map to keep track of already seen items.
The example shows integers but the problem statement does not mention any restrictions on the types. Will this work on any type?