2778. Sum of Squares of Special Elements
约 1 分钟
LeetCode 每日一题:Sum of Squares of Special Elements
You are given a 1-indexed integer array nums of length n.
An element nums[i] of nums is called special if i divides n, i.e. n % i == 0.
Return the sum of the squares of all special elements of nums.
Constraints:
1 <= nums.length == n <= 501 <= nums[i] <= 50
思路
白给的题 太简单了
python
class Solution:
def sumOfSquares(self, nums: List[int]) -> int:
return sum([num**2 for i, num in enumerate(nums) if len(nums) % (i+1) == 0])系列每日一题 →
标签看图写话