본문 바로가기
python-algorithm

leetcode 2465. Number of Distinct Averages

by 무적김두칠 2023. 1. 19.

https://leetcode.com/problems/number-of-distinct-averages/description/

 

Number of Distinct Averages - LeetCode

Number of Distinct Averages - You are given a 0-indexed integer array nums of even length. As long as nums is not empty, you must repetitively: * Find the minimum number in nums and remove it. * Find the maximum number in nums and remove it. * Calculate th

leetcode.com

 

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution:
    def distinctAverages(self, nums: List[int]) -> int:
        avg_list = []
        nums.sort()
 
        for i in range(len(nums)//2):
            avg_list.append(nums[0+i]+nums[-(i+1)])
        avg_list = list(set(avg_list))
 
        answer = len(avg_list)
 
        return answer
        
cs
반응형

댓글