IT/코딩테스트
[Leetcode] 2913. Subarrays Distinct Element Sum of Squares I
이주디
2024. 2. 24. 14:41
728x90
https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i
Subarrays Distinct Element Sum of Squares I - LeetCode
Can you solve this real interview question? Subarrays Distinct Element Sum of Squares I - You are given a 0-indexed integer array nums. The distinct count of a subarray of nums is defined as: * Let nums[i..j] be a subarray of nums consisting of all the ind
leetcode.com
class Solution:
def sumCounts(self, nums: List[int]) -> int:
count = 0
subarrays = []
for i in range(1, len(nums)+1):
for j in range(len(nums)-i+1):
subarrays.append(nums[j:i+j])
for sub in subarrays:
sub = list(set(sub))
count += len(sub) * len(sub)
return count
728x90