Problem Solving/LeetCode
2023.11.19 Today's Challenge
fabichoi
2023. 11. 19. 23:45
https://leetcode.com/problems/reduction-operations-to-make-the-array-elements-equal/
Reduction Operations to Make the Array Elements Equal - LeetCode
Can you solve this real interview question? Reduction Operations to Make the Array Elements Equal - Given an integer array nums, your goal is to make all elements in nums equal. To complete one operation, follow these steps: 1. Find the largest value in nu
leetcode.com
생각보다 쉬운 문제
class Solution:
def reductionOperations(self, nums: List[int]) -> int:
nums.sort()
ans, up = 0, 0
for i in range(1, len(nums)):
if nums[i] != nums[i-1]:
up += 1
ans += up
return ans
반응형