Back to course home
0% completed
Vote For New Content
Easy 1 line Python solution
Nabeel Keblawi
Oct 3, 2024
I know we're using 2 pointers and that was my initial solution, but the challenge was it kept swapping even after all non-duplicate values were found. So I found an easier shortcut with one line of code:
return len(set(arr))
And it passed all test cases. But if we insist on using two pointers to solve this one, I'd go with the provided solution.
0
2
Comments
Comments
A
anifahammid 10 months ago
This creates a set from the arr and returns the length. Creating the new set - already uses extra space, which is against the requirement
On this page
Problem Statement
Try it yourself