Three stones are placed on the number line, respectively, the position of a, b, c.
Each round, we assume that three stones are located at the current position x, y, z and x <y <z. From the position x or z is a position to pick up a stone, and the stone is moved to a position k an integer, wherein x <k <z and k! = Y.
When you can not make any movement, that is, the position of these stones in a row, the game ends.
To make the game ends, the minimum and maximum number of moves you can perform are how much? Return key to form an array of length 2: answer = [minimum_moves, maximum_moves]
Example 1:
Input: a = 1, b = 2, c = 5 Output: [1, 2]
Explanation: The stones move from 4 to 5 and then moved to 3, or we can directly move the stone to 3.
Example 2:
Input: a = 4, b = 3, c = 2 Output: [0, 0]
Explanation: We can not make any move.
Source: stay button (LeetCode) link: https: //leetcode-cn.com/problems/moving-stones-until-consecutive network all the copyright collar button.
. 1 public int [] numMovesStones ( int A, int B, int C) { 2 int [] RES = new new int [2 ]; . 3 // For a start, do not know a, b, c which large which small . 4 int X = math.min (A, math.min (B, C)); . 5 int Z = Math.max (A, Math.max (B, C)); . 6 int Y = A + B + CX- Z; . 7 / / now X <Y <Z . 8 IF (X + 2 <Z-Y && 2> Y) { // maximum where the minimum number of steps is 2, i.e. x, y, z is greater than 2 separately . 9 RES [0] = 2 ; 10 } the else IF (X + Y +. 1. 1 && == Y == Z) { // the minimum case where the minimum number of steps is 0, i.e., when three consecutive number . 11 RES [0] = 0 ; 12 is } the else { // other cases i.e., 134 or 235, or 135 of these types of cases is the minimum number of steps. 1 13 is RES [0] =. 1 ; 14 } 15 RES [. 1] = ZX-1-1 of; // maximum value is on both sides x, z and approached Y 16 return RES; . 17 }