Given three integers x, y, and z, return:
Example Input: x = 3, y = 7, z = 5
Step-by-step execution:
| xStepNeed = | 3-5 | = 2 |
| yStepNeed = | 7-5 | = 2 |
class Solution {
public int findClosest(int x, int y, int z) {
int xStepNeed = Math.abs(x - z);
int yStepNeed = Math.abs(y - z);
if (xStepNeed < yStepNeed) return 1;
else if (xStepNeed > yStepNeed) return 2;
else return 0;
}
}