11"""
22You are given an array nums of n positive integers.
33
4- You can perform two types of operations on any
4+ You can perform two types of operations on any
55element of the array any number of times:
66
77If the element is even, divide it by 2.
8- For example, if the array is [1,2,3,4], then you can do this operation
8+ For example, if the array is [1,2,3,4], then you can do this operation
99on the last element, and the array will be [1,2,3,2].
1010If the element is odd, multiply it by 2.
1111For example, if the array is [1,2,3,4], then you can do this operation
1212on the first element, and the array will be [2,2,3,4].
13- The deviation of the array is the maximum difference between
13+ The deviation of the array is the maximum difference between
1414any two elements in the array.
1515
16- Return the minimum deviation the array can have after performing
16+ Return the minimum deviation the array can have after performing
1717some number of operations.
1818"""
1919
2020from heapq import heapify , heappop , heappush
21-
21+
2222
2323class Solution :
2424 def minimum_deviation (self , nums ) -> int :
@@ -29,7 +29,7 @@ def minimum_deviation(self, nums) -> int:
2929 nums (List[int]): A list of positive integers.
3030
3131 Returns:
32- temp_mindeviation (int): The minimum deviation of the array after operations.
32+ temp_mindeviation (int): The minimum deviation of array after operations.
3333
3434 Examples:
3535 >>> solution = Solution()
@@ -45,11 +45,11 @@ def minimum_deviation(self, nums) -> int:
4545 temp_min = - min (heapque , key = lambda num : - num )
4646 temp_mindeviation = - heapque [0 ] - temp_min
4747
48- while h and h [0 ] % 2 == 0 :
49- n = heappop (h ) // 2
50- heappush (h , n )
48+ while heapque and heapque [0 ] % 2 == 0 :
49+ n = heappop (heapque ) // 2
50+ heappush (heapque , n )
5151 temp_min = min (temp_min , - n )
52- temp_mindeviation = min (temp_mindeviation , - h [0 ] - temp_min )
52+ temp_mindeviation = min (temp_mindeviation , - heapque [0 ] - temp_min )
5353
5454 return temp_mindeviation
5555
0 commit comments