728x90
https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i
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
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 2103. Rings and Rods (1) | 2024.02.25 |
---|---|
[Leetcode] 1347. Minimum Number of Steps to Make Two Strings Anagram (1) | 2024.02.24 |
[Leetcode] 2956. Find Common Elements Between Two Arrays (0) | 2024.02.23 |
[Leetcode] 804. Unique Morse Code Words (0) | 2024.02.23 |
[Leetcode] 1684. Count the Number of Consistent Strings (0) | 2024.02.23 |