From 51445b727f2fbb61e9e85910ac61029f521fedff Mon Sep 17 00:00:00 2001 From: ferhat elmas Date: Tue, 14 Nov 2023 12:41:40 +0100 Subject: [PATCH] leetcode subarrays distinct element sum of squares --- .../easy/subarrays_distinct_element_sum_of_squares.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 leetcode/algorithms/easy/subarrays_distinct_element_sum_of_squares.py diff --git a/leetcode/algorithms/easy/subarrays_distinct_element_sum_of_squares.py b/leetcode/algorithms/easy/subarrays_distinct_element_sum_of_squares.py new file mode 100644 index 00000000..a6ff9ce8 --- /dev/null +++ b/leetcode/algorithms/easy/subarrays_distinct_element_sum_of_squares.py @@ -0,0 +1,11 @@ +from typing import List + + +class Solution: + def sumCounts(self, nums: List[int]) -> int: + s, l = 0, len(nums) + for i in range(1, l + 1): + for j in range(0, l - i + 1): + n = len(set(nums[j : j + i])) + s += n * n + return s