https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i/description/
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
1 2 3 4 5 6 7 8 9 10 11 12 13 | class Solution: def sumCounts(self, nums: List[int]) -> int: answer = 0 cnt = 1 for i in range(len(nums), 0, -1): for j in range(i): distinct_nums = list(set(nums[j: j + cnt])) answer += (len(distinct_nums) ** 2) cnt += 1 return answer | cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 645. Set Mismatch (0) | 2024.01.22 |
---|---|
leetcode 1207. Unique Number of Occurrences (0) | 2024.01.17 |
leetcode 3005. Count Elements With Maximum Frequency (0) | 2024.01.15 |
leetcode 917. Reverse Only Letters (0) | 2024.01.13 |
leetcode 1304. Find N Unique Integers Sum up to Zero (0) | 2024.01.10 |
댓글