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 |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 58. Length of Last Word (0) | 2023.01.21 |
---|---|
leetcode 2404. Most Frequent Even Element (0) | 2023.01.19 |
leetcode 2496. Maximum Value of a String in an Array (0) | 2023.01.19 |
leetcode 2535. Difference Between Element Sum and Digit Sum of an Array (0) | 2023.01.17 |
leetcode 326. Power of Three (0) | 2023.01.17 |
댓글