class Solution:
def countQuadruplets(self, nums: List[int]) -> int:
cnt = 0
if len(nums) < 4:
return cnt
# nums.sort()
for a in range(len(nums)-3):
for b in range(a+1, len(nums)-2):
for c in range(b+1, len(nums)-1):
for d in range(c+1, len(nums)):
if nums[a] + nums[b] + nums[c] == nums[d]:
cnt += 1
return cnt
算法复杂度太高了,刚刚过AC,TODO降低时间复杂度