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?
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
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.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?