6275. Make all the minimum operations of all elements in the array II
Thought:
Weekly Two Questions!!!
·First use the list derivative to calculate the difference between each element。
·Then,Initialize a counter to track the required operations required。
·The difference between traversing,And check whether each difference can be removed。
·if not,Then return -1,Because the array cannot be equal to the given operation。
·If it is eliminated,It removes the absolute value of the difference to add to the counter。
·at last,It returns the required number of operations。
for example:
[3,0,-6,3]
It is every positive number divided by3In harmony,Tested many times,是因为at last一种特殊情况(When two list items, etc.)No consideration。
Code:
1 | class Solution: |