2777. Find the Distinct Difference Array
My accepted Python solution to LeetCode problem 2777, Find the Distinct Difference Array, running in 23ms.
- Difficulty: Easy
- Python
- Runtime 23ms
- Memory 12.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 23ms, memory 12.5MB, accepted 2025-12-24.
class Solution(object):
def distinctDifferenceArray(self, nums):
n = len(nums)
result = []
for i in range(n):
prefix = len(set(nums[:i+1]))
suffix = len(set(nums[i+1:]))
result.append(prefix - suffix)
return result