Bingo! This is a prefect answer:-) So in the process of transformation, whenever we detected abs(a[i] - a[i + 1]) == 1, the program should immediately output -1.
Should be (a[i]+a[i+1])#2 '=0 which means the sum of these two number is odd . This way, you can output -1 earlier.
【在 H****S 的大作中提到】 : Bingo! This is a prefect answer:-) So in the process of transformation, : whenever we detected abs(a[i] - a[i + 1]) == 1, the program should : immediately output -1. : : array
The final equal number needs to be equal to the average of all numbers. Otherwise it is not minimum. The number of changes is the sum of abs(num-ave ).