Back to course home
0% completed
Vote For New Content
[Spoiler] Not cutting corners
John O'Neill
Sep 13, 2023
The problem as evaluated by the code runner doesn't actually require removing duplicates — it just requires counting non-duplicates, which isn't really a two pointers problem. To keep myself honest, I actually removed the duplicates, as below.
class Solution: def remove(self, arr): if not arr: return 0 next_non_duplicate = 1 for i, num in enumerate(arr): if arr[next_non_duplicate - 1] != num: arr[next_non_duplicate] = num next_non_duplicate += 1 n = len(arr) for _ in range(next_non_duplicate, n): arr.pop() return len(arr)
3
0
Comments
Comments
On this page
Problem Statement
Try it yourself